The script uses the `PROC SGPLOT` procedure to create two distinct plots. The first plot shows the distribution of the 'horsepower' variable from the `sashelp.cars` dataset by superimposing a normal density estimate and a kernel density estimate. The second plot compares the distributions of the 'MSRP' and 'Invoice' variables from the same dataset. Each plot is generated in a separate PNG file using ODS (Output Delivery System) instructions that define the output path, dimensions, and image name.
Data Analysis
Type : SASHELP
The data comes from the `sashelp.cars` table, which is a standard data library provided with SAS.
1 Code Block
PROC SGPLOT
Explanation : This block first configures the ODS environment to save the plots in a specified directory. Then, it uses `PROC SGPLOT` to create a density plot for the 'horsepower' variable from the `sashelp.cars` table. The plot superimposes a normal density curve and a kernel density curve to compare the distributions. The output is a PNG image named 'density1.png'.
Copied!
ods listing gpath="/home/nicolasdupont0/resources_github/Graph/Distribution/img" image_dpi=200;
*---------------------------------------------------;
ods graphics /
reset = all attrpriority=color border = no width = 600px height = 400px
imagename = "density1" imagefmt = png outputfmt = png antialiasmax = 10000;
title '1# Distribution of the numerical variable horsepower in the cars dataset';
proc sgplot data=sashelp.cars;
title "1# horsepower Density";
density horsepower / type=normal scale=percent legendlabel="Normal";
density horsepower / type=kernel scale=percent legendlabel="kernel";
xaxis min=0;
yaxis min=0;
run;
title '1# Distribution of the numerical variable horsepower in the cars dataset';
9
PROC SGPLOTDATA=sashelp.cars;
10
title "1# horsepower Density";
11
density horsepower / type=normal scale=percent legendlabel="Normal";
12
density horsepower / type=kernel scale=percent legendlabel="kernel";
13
xaxis min=0;
14
yaxis min=0;
15
RUN;
2 Code Block
PROC SGPLOT
Explanation : This second `PROC SGPLOT` block generates a plot comparing the density distributions of the 'MSRP' and 'Invoice' variables from the `sashelp.cars` table. Both curves are displayed on the same plot for direct comparison, with a legend to identify them. The output is a PNG image named 'density2.png'.
Copied!
*---------------------------------------------------;
ods graphics /
reset = all attrpriority=color border = no width = 600px height = 400px
imagename = "density2" imagefmt = png outputfmt = png antialiasmax = 10000;
title '2# Distribution of two numerical variables MSRP and Invoice from the cars dataset';
proc sgplot data=sashelp.cars;
title "2# MSRP and Invoice Density";
density MSRP / scale=percent name="MSRP" legendlabel="MSRP";
density Invoice / scale=percent name="Invoice" legendlabel="Invoice";
xaxis label="Distribution" min=0;
yaxis label="%" min=0;
keylegend "MSRP" "Invoice" / across=1 position=Topleft location=Inside;
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.