Reproducible Reporting with Quarto and SAS

Author

Ran Li (Maintainer)

Published

October 1, 2024

Code
library(SASmarkdown)

Components

Code

This is just a basic example of a SAS code block.

This is 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 step
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.

Statiatsics step
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
    ------------------------------------------------------------------

HTML Plots

HTML Correlation Matrix Code
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
 
Scatter Plot Matrix Scatter Plot Matrix 60 80 100 120 140 50 55 60 65 70 11 12 13 14 15 16 60 80 100 120 140 50 55 60 65 70 11 12 13 14 15 16 Weight Height Age

SAS Logs

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
 -------------------------------------------------------------------------