The script uses the 'cars' dataset from the 'SASHELP' library, which is an example dataset provided with SAS and accessible by default.
1 Code Block
DATA STEP Data
Explanation : This DATA block creates a new dataset named 'mycars' by copying observations from the 'sashelp.cars' dataset. It then calculates a new variable 'AvgMPG' as the mean of 'mpg_city' and 'mpg_highway' for each observation.
Copied!
data mycars;
set sashelp.cars;
AvgMPG=mean(mpg_city, mpg_highway);
run;
1
DATA mycars;
2
SET sashelp.cars;
3
AvgMPG=mean(mpg_city, mpg_highway);
4
RUN;
2 Code Block
PROC PRINT
Explanation : This block uses PROC PRINT to display the contents of the 'mycars' dataset. It selects the variables 'make', 'model', 'type', and 'avgmpg' and filters observations to include only those where 'AvgMPG' is greater than 35. A title is also applied to the report.
Copied!
title "Cars with Average MPG Over 35";
proc print data=mycars;
var make model type avgmpg;
where AvgMPG > 35;
run;
1
title "Cars with Average MPG Over 35";
2
PROC PRINTDATA=mycars;
3
var make model type avgmpg;
4
where AvgMPG > 35;
5
RUN;
3 Code Block
PROC MEANS
Explanation : This block uses PROC MEANS to calculate descriptive statistics (mean, minimum, maximum) for the 'avgmpg' variable from the 'mycars' dataset. The results are grouped by the 'type' variable and displayed with one decimal place. A title is applied to the report. The final TITLE; command resets global titles.
Copied!
title "Average MPG by Car Type";
proc means data=mycars
mean min max maxdec=1;
var avgmpg;
class type;
RUN;
TITLE;
1
title "Average MPG by Car Type";
2
PROC MEANSDATA=mycars
3
mean min max maxdec=1;
4
var avgmpg;
5
class type;
6
RUN;
7
TITLE;
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.