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!
DATA WORK.CARS_SAMPLE1;
set SASHELP.CARS;
RUN;
1
DATA WORK.CARS_SAMPLE1;
2
SET SASHELP.CARS;
3
RUN;
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!
PROC PRINT DATA=CARS_SAMPLE1 (OBS=10);
RUN;
1
PROC PRINTDATA=CARS_SAMPLE1 (OBS=10);
2
RUN;
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!
PROC SUMMARY DATA=CARS_SAMPLE1;
1
PROC SUMMARYDATA=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!
PROC SUMMARY DATA=CARS_SAMPLE1 PRINT;
1
PROC SUMMARYDATA=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.
VAR MSRP Invoice EngineSize Cylinders Horsepower MPG_City MPG_Highway Wheelbase LENGTH;
3
class TYPE;
4
OUTPUT mean=MSRP LENGTH out=CARS_STATS_SUMMARY;
5
RUN;
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.