I talked a little while ago about downloading R. Time to update you on progress since I ran through some of the sample code in the Introduction to R.
Well, I couldn’t quite believe how simple the syntax is, it feels quite strange using <- all over the place, and not a proc in sight (R exposes functionality through functions).
Moving very slightly forwards from the intro code I wrote, with a bit of trial and error, the following:
The "exciting" thing about this rather mundane code is that the read.ssd() function is reading a SAS® dataset into R! Reading a SAS dataset is no more difficult than loading the "foreign" library, and then passing the path, the dataset name (without the .sas7bdat extension), and the path to sas.exe.
The dataset is fairly dull - it has two variables x and y, where y is x plus x times a random amount between 0 and 1.
The attach() function makes the dataset available as a data frame, the summary() function gives basic summary stats, the lm() function is equivalent to proc reg, and stores the regression coefficients to a new variable structure fm.
Another call to fm() gives me linear regression coefficients (the m and c, from y = mx + c) and goodness of fit statistics.
Finally the calls to plot() and abline() plot a chart of observations, overlayed with a line of best fit.
Not very interesting but: (a) reading SAS data into R is quick and easy; (b) writing R code is quick and easy; (c) the results from the R code were verified by those produced in SAS.
Point (c) isn't much of a surprise - but the painlessness of both (a) and (b) is!
R – first steps
I talked a little while ago about downloading R. Time to update you on progress since I ran through some of the sample code in the Introduction to R.
Well, I couldn’t quite believe how simple the syntax is, it feels quite strange using
<-all over the place, and not aprocin sight (R exposes functionality through functions).Moving very slightly forwards from the intro code I wrote, with a bit of trial and error, the following:
And it worked!
The "exciting" thing about this rather mundane code is that the
read.ssd()function is reading a SAS® dataset into R! Reading a SAS dataset is no more difficult than loading the "foreign" library, and then passing the path, the dataset name (without the .sas7bdat extension), and the path to sas.exe.The dataset is fairly dull - it has two variables x and y, where y is x plus x times a random amount between 0 and 1.
The
attach()function makes the dataset available as a data frame, thesummary()function gives basic summary stats, thelm()function is equivalent toproc reg, and stores the regression coefficients to a new variable structure fm.Another call to
fm()gives me linear regression coefficients (the m and c, from y = mx + c) and goodness of fit statistics.Finally the calls to
plot()andabline()plot a chart of observations, overlayed with a line of best fit.Not very interesting but: (a) reading SAS data into R is quick and easy; (b) writing R code is quick and easy; (c) the results from the R code were verified by those produced in SAS.
Point (c) isn't much of a surprise - but the painlessness of both (a) and (b) is!
I look forward with great interest to hear what comes out of the SAS Global Forum in a few days time!
Technorati Tags: data, r, SAS