Published on :
Reporting SASHELP

PROC SUMMARY and PROC PRINT Analysis

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a sample of the SASHELP.CARS dataset, named CARS_SAMPLE1, in the WORK library. Then, it uses PROC PRINT to display the first 10 observations of this new dataset. The main part of the script explores PROC SUMMARY: first without the PRINT option (which suppresses the default output), then with the PRINT option to display the number of observations. Finally, it shows a more advanced use of PROC SUMMARY with specified variables, a grouping variable (CLASS), and an OUTPUT statement to create a new dataset containing the calculated statistics.
Data Analysis

Type : SASHELP


The source data comes from the built-in SASHELP.CARS dataset, which is a standard system dataset in SAS. The script then creates intermediate datasets (WORK.CARS_SAMPLE1 and CARS_STATS_SUMMARY) based on this SASHELP data.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a new temporary dataset named CARS_SAMPLE1 in the WORK library by copying all observations and variables from the SASHELP.CARS dataset. This is a common practice for manipulating a copy of the data without affecting the original.
Copied!
1DATA WORK.CARS_SAMPLE1;
2 SET SASHELP.CARS;
3RUN;
2 Code Block
PROC PRINT
Explanation :
This PROC PRINT procedure displays the first 10 observations of the CARS_SAMPLE1 dataset. The '(OBS=10)' option is used to limit the number of rows displayed, which is useful for a quick overview of the data.
Copied!
1PROC PRINT DATA=CARS_SAMPLE1 (OBS=10);
2RUN;
3 Code Block
PROC SUMMARY
Explanation :
This call to PROC SUMMARY calculates descriptive statistics for the CARS_SAMPLE1 dataset. Without the PRINT option, the procedure suppresses the output of statistical results to the default ODS destination. This means no statistics table will be displayed in the log or results window.
Copied!
1PROC SUMMARY DATA=CARS_SAMPLE1;
4 Code Block
PROC SUMMARY
Explanation :
By including the PRINT option, this execution of PROC SUMMARY displays the default statistics (usually the number of observations 'N') in the ODS output. Since no variables are specified in a VAR statement, it only provides the total number of observations for the entire dataset.
Copied!
1PROC SUMMARY DATA=CARS_SAMPLE1 PRINT;
5 Code Block
PROC SUMMARY Data
Explanation :
This block uses PROC SUMMARY more comprehensively. It calculates descriptive statistics (mean by default and the mean for 'MSRP' and 'Length' via the OUTPUT statement) for the variables specified in the VAR statement. The CLASS TYPE statement groups these statistics by the different categories of the TYPE variable. Finally, the OUTPUT statement creates a new dataset named CARS_STATS_SUMMARY which contains the calculated means for each TYPE group.
Copied!
1PROC SUMMARY DATA=CARS_SAMPLE1 PRINT;
2VAR MSRP Invoice EngineSize Cylinders Horsepower MPG_City MPG_Highway Wheelbase LENGTH;
3class TYPE;
4OUTPUT mean=MSRP LENGTH out=CARS_STATS_SUMMARY;
5RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.