Which Base procedure is best for simple statistics?

It’s an understatement to say there are many Base SAS procedures!

Some procedures may be used for basic report writing. Other procedures may be used to perform statistical analysis. Some have similar functions. Others are unique in the output that they can produce. Which procedure you choose generally depends on the type of output you are trying to generate—with perhaps a bit of personal preference sprinkled into the mix

I often get calls from SAS users who are trying sort through the options and thought a blog post illustrating a few alternatives might help you choose the procedure that’s the best fit for your needs. Here are a few common choices for calculating frequency, percentages and a few other simple statistics, but you can certainly use other Base SAS procedures or DATA step processing to perform these calculations. I’ve also included a few notes on customizing calculations and output.

It’s helpful to note that Base procedures have specific keywords to refer to statistics. For future reference, you might want to bookmark this table of common procedures and the simple statistics.

Calculating frequency

If you need to generate basic frequency (N) or sum reports, you can use a number of Base procedures.

PROC PRINT allows you to get a frequency count within a BY group and across the entire data set. In addition, PROC PRINT can create summarized values of numeric variables, also within a BY group and for the entire data set.

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 allows for more customized grouping and display of variable values, and it supports the computation of new variables within COMPUTE blocks.

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;

PROC FREQ is another procedure that outputs basic frequency counts. This procedure will group like variable values together and return the frequency count for the grouping. PROC FREQ 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 get the distinct count of a variable’s values, you can use PROC FREQ with the NLEVELS option.

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

Calculating percentages

PROC FREQ, by default, outputs percentages for multi-way tables, representing overall, row, and column percents.

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

PROC TABULATE outputs comparable percentages using the following statistic keywords: PCTN, ROWPCTN, and COLPCTN.

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

PROC TABULATE has the added ability to generate more advanced denominator definitions. You will find the SAS Global Forum 2013 paper Tips for Generating Percentages Using the SAS® TABULATE Procedure helpful.

PROC REPORT uses the PCTN statistic to generate a column percentage. Other custom percentages and be computed in PROC REPORT using COMPUTE blocks.

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

Calculating other statistics

SAS Base procedures MEANS, SUMMARY, REPORT and TABULATE can calculate many statistics as highlighted in the table of common procedures and the simple statistics.

PROC TABULATE and PROC REPORT have a report-friendly tabular structure.

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

PROC SUMMARY or PROC MEANS are recommended if you need to create an output data set for your requested statistics. These two procedures are essentially the same except for a few defaults:

PROC SUMMARY does not create printed output by default, but PROC MEANS does.

Another difference is if you omit the VAR statement, PROC SUMMARY creates a simple frequency count of observations, but PROC MEANS analyzes all numeric variables that are not listed on other statements.

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

proc print data=stats;
run;

Customizing calculations, summaries and output

If your output needs to include customized summaries using IF/THEN logic, then PROC REPORT is the procedure to choose with its’ COMPUTE blocks and LINE statements. The SAS Samples below illustrate how to:

Flag a row and add a conditional footnote at the end of a page with PROC REPORT

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). Here is an example to Demonstrate the use of banding in PROC TABULATE.

Which Base procedure is best for simple statistics? was published on SAS Users.