Code
library(SASmarkdown)
library(SASmarkdown)
This is just a basic example of a SAS code block.
proc means data=sashelp.class;
run;
The MEANS Procedure
Variable N Mean Std Dev Minimum Maximum
-------------------------------------------------------------------------
Age 19 13.3157895 1.4926722 11.0000000 16.0000000
Height 19 62.3368421 5.1270752 51.3000000 72.0000000
Weight 19 100.0263158 22.7739335 50.5000000 150.0000000
-------------------------------------------------------------------------
As you can see the output is just display here.
One interested we can do is to pass data between code chunks. Lets say the first code block is a DATA cleaning step, explaining how we calculated a new variable. Specify the collectcode chunk option to have this DATA step “carry over” in (all of) the following code blocks.
This is written as:
data class;
set sashelp.class;
bmi = 703*weight/height**2;
run;
Next, we have a separate code block that uses the data. This is just a plain SAS code block.
proc means data=class;
var bmi;
run;
The MEANS Procedure
Analysis Variable : bmi
N Mean Std Dev Minimum Maximum
------------------------------------------------------------------
19 17.8632519 2.0926193 13.4900007 21.4296601
------------------------------------------------------------------
ods html5 style=htmlblue;
proc corr data=sashelp.class plots=matrix;
run;
3 Variables: | Age Height Weight |
---|
Simple Statistics | ||||||
---|---|---|---|---|---|---|
Variable | N | Mean | Std Dev | Sum | Minimum | Maximum |
Age | 19 | 13.31579 | 1.49267 | 253.00000 | 11.00000 | 16.00000 |
Height | 19 | 62.33684 | 5.12708 | 1184 | 51.30000 | 72.00000 |
Weight | 19 | 100.02632 | 22.77393 | 1901 | 50.50000 | 150.00000 |
Pearson Correlation Coefficients, N = 19 Prob > |r| under H0: Rho=0 |
|||
---|---|---|---|
Age | Height | Weight | |
Age |
1.00000
|
0.81143
<.0001
|
0.74089
0.0003
|
Height |
0.81143
<.0001
|
1.00000
|
0.87779
<.0001
|
Weight |
0.74089
0.0003
|
0.87779
<.0001
|
1.00000
|
SAS is unusual software in that it generates two distinct output streams. In addition to the typical tables and graphs (in a variety of formats, including text and html), SAS echos your code and writes notes and messages in a separate log file. These are important so lets include that here.
2 proc means data=sashelp.class;
3 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The PROCEDURE MEANS printed page 1.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.04 seconds
cpu time 0.04 seconds
The MEANS Procedure
Variable N Mean Std Dev Minimum Maximum
-------------------------------------------------------------------------
Age 19 13.3157895 1.4926722 11.0000000 16.0000000
Height 19 62.3368421 5.1270752 51.3000000 72.0000000
Weight 19 100.0263158 22.7739335 50.5000000 150.0000000
-------------------------------------------------------------------------