Tips for determining which Base SAS® procedure to choose


There are many Base SAS procedures; some have similar functions, and others are unique in the output that they can produce. Procedures might be used for basic report writing, or they might be used to perform statistical analyses. The procedure that you choose depends on the type of output that you are trying to generate. The examples below will guide you in making the best choice to meet your needs. Other procedures or DATA step processing could also be used, but this note illustrates a few alternatives. The procedures have specific keywords to refer to statistics. The link below shows a table of common procedures and the statistics that they support.

Keywords and Formulas


If you need to generate basic frequency (N) or sum reports, you can use the PRINT procedure or the REPORT procedure.

proc sort data=sashelp.class out=class;                   
   by sex;                                                
run;                         
                                                          
proc print data=class noobs                               
           sumlabel='Subtotal' grandtotal_label='Grand Total';   
   by sex;                                                
   var name age height weight;                            
   sum height weight;                                     
run;

proc report data=sashelp.class nowd;
   column sex age height weight bmi;
   define sex / group;
   define age / group;
   define height / sum;
   define weight / sum;
   define bmi / computed format=8.2;

   compute bmi;
      bmi=(weight.sum/(height.sum)**2)*703;
   endcomp;
run;


Another procedure that generates basic frequency counts is the FREQ procedure. This procedure groups like variable values together and returns the frequency count for the grouping. The FREQ procedure also has the ability to create an output data set.

proc freq data=sashelp.class;
   tables age*sex / out=new outpct;
run;

proc print data=new;
run;


If you want to obtain the distinct count of a variable's values, you can use the FREQ procedure with the NLEVELS option.

proc freq data=sashelp.class nlevels;
   tables age;
run;


If you need more advanced statistics and an output data set, the MEANS procedure or the SUMMARY procedure are recommended.

proc summary data=sashelp.class;
   class age;
   var height weight;
   output out=stats sum= mean= min= max= / autoname;
run;

proc print data=stats;
run;


The TABULATE procedure can generate the same statistics, and it also has a report-friendly tabular structure.

proc tabulate data=sashelp.class;
   class age;
   var height weight;
   table age, (height weight)*(sum mean min max);
run;


If percentages are needed, either the FREQ, REPORT, or TABULATE procedure can be used.

proc freq data=sashelp.class;
   tables age*sex;
run;

proc tabulate data=sashelp.class;
   class age sex;
   table age*(n pctn rowpctn colpctn) all*(n rowpctn), sex all;
run;

proc report data=sashelp.class nowd;
   column age sex,(n pctn);
   define age / group;
   define sex / across;
   define pctn / format=percent8.2 'Col %';
run;

The TABULATE procedure has the added ability to generate more advanced denominator definitions. The link below is to a paper from SAS Global Forum 2013 on this topic:

Tips for Generating Percentages Using the SAS® TABULATE Procedure

If your output needs to include customized summaries using IF/THEN logic, then REPORT is the procedure to choose with its COMPUTE blocks and LINE statements. The SAS Sample below illustrates this.

Usage Note 24536: How do I create multiple summary rows without using a LINE statement?

Finally, any of these procedures can be customized and output to any destination, including Excel, RTF, PDF, and HTML, using the Output Delivery System (ODS).

Sample 25401: Demonstrate the use of banding in PROC TABULATE