✅ All About PROC SUMMARY in SAS: A Comprehensive Guide with Practical Examples

📘 Introduction

PROC SUMMARY in SAS is a powerful procedure used to generate summary statistics for numeric variables. It is often considered functionally equivalent to PROC MEANS but with more flexibility in generating customized outputs and silent summaries.

In this guide, you'll learn:

  • Complete syntax of PROC SUMMARY
  • All available options and statements
  • Grouped examples
  • How it differs from PROC MEANS
  • Output datasets and tips

Proc Summary in SAS - Datahark.in


🛠 Syntax of PROC SUMMARY

PROC SUMMARY <options>;
VAR variable(s); CLASS variable(s); BY variable(s); OUTPUT OUT=dataset <stat-options>; RUN;

⚙️ Common Options in PROC SUMMARY

OptionDescription
DATA=Specifies the input dataset
NCount of non-missing values
MEANMean or average value
STDStandard deviation
MINMinimum value
MAXMaximum value
SUMTotal sum
MAXDEC=Maximum number of decimals
NWAYOutputs only rows with all CLASS variables present
CHARTYPEAdds a TYPE variable to output

📄 Statements in PROC SUMMARY

StatementPurpose
VARSpecifies numeric variables to analyze
CLASSGroup summary statistics by categorical variables
BYBY-group processing; data must be sorted
OUTPUTOutputs summary statistics to a dataset

✅ PROC SUMMARY vs PROC MEANS

FeaturePROC MEANSPROC SUMMARY
Displays outputYes (default)No (unless PRINT)
FlexibilityModerateHigh
Use in productionFor display/reviewFor data pipelines
Output datasetOptionalCommon

🧪 Examples of PROC SUMMARY

Example 1: Basic Summary Statistics

proc summary data=sashelp.class print;
run;

Note: Use PRINT to display output.


Example 2: Specifying Variables

proc summary data=sashelp.class print;
var height weight; run;

Example 3: Using CLASS Statement

proc summary data=sashelp.class print;
class sex; var height weight; run;

Example 4: Creating Output Dataset

proc summary data=sashelp.class n mean maxdec=1;
class sex; var height weight; output out=summary_stats; run;

Example 5: Custom Output Variable Names

proc summary data=sashelp.class;
class sex; var weight; output out=summary_data mean=mean_weight max=max_weight min=min_weight; run;

Example 6: Using BY Statement (sorted data)

proc sort data=sashelp.class out=sorted;
by sex; run; proc summary data=sorted print; by sex; var height; run;

🔄 Output Options in PROC SUMMARY

You can customize the summary stats by combining the following keywords in the OUTPUT statement:

KeywordDescription
N=Assigns name to N (count)
MEAN=Assigns name to mean
STD=Standard deviation
SUM=Assigns name to sum
MIN=Assigns name to minimum
MAX=Assigns name to maximum

Example:

output out=myout n=n_obs mean=avg std=stdev;

🧠 Tips for PROC SUMMARY

  • Always use PRINT if you want to display results.
  • Use NWAY if you need only fully classified combinations.
  • Use meaningful output variable names with =.
  • Great for creating reusable summary datasets.


📦 Summary Table

FeatureDescription
Primary UseSummary statistics
Shows OutputNo (by default)
Supports GroupsYes (CLASS or BY)
Custom OutputYes (OUTPUT statement)
Output DatasetYes
Flexible OutputHighly customizable

 

Keywords: PROC SUMMARY SAS, SAS summary statistics, SAS aggregate data, PROC SUMMARY vs PROC MEANS, output statistics SAS, SAS class by var output


Post a Comment

0 Comments