BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jonate_H
Quartz | Level 8

I am using proc sgplot to plot CDF (series statement) and PDF (density statement) for a dataset. 

Does it always require to choose the distribution assumption? e.g., type= normal

Is it possible to plot CDF and PDF witout underline distribution assumption? and if, how to achieve that?

Many thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

For continuous distributions, the easiest way is to use PROC UNIVARIATE to create the CDF and PDF plots. The HISTOGRAM statement fits and optionally overlays a nonparamwetric kernel density estimate. The CDFPLOT statement displays the empirical CDF. Here is an example:

 

proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / kernel;  /* nonparametric density estimate */
cdfplot mpg_highway;
ods select Histogram CDFPlot;
run;

You can also fit and overlay parametric distributions. PROC UNIVARIATE supports about 20 common distributions. Here is an example of fitting lognormal distribution (maximum likelihood estimation) to the same data:

proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / lognormal;  /* overlay PDF */
cdfplot   mpg_highway / lognormal;  /* overlay CDF */
ods select Histogram CDFPlot;
run;

 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Not sure if this is what you're asking, but you can plot densities and distributions in PROC SGPLOT like this

 

data normal;
   do x = -3 to 3 by 0.01;
      y_pdf = pdf('normal',x);
      y_cdf = cdf('normal',x);
      output;
   end;
run;

title 'Normal Distribution';
proc sgplot data = normal;
band x = x upper = y_pdf lower = 0 / legendlabel = 'Density';
series x = x y = y_cdf / legendlabel = 'CDF';

keylegend / location = inside position = topleft across = 1; 
yaxis label = 'Density/Probability';
xaxis label = 'x';
run;
title;
Rick_SAS
SAS Super FREQ

For continuous distributions, the easiest way is to use PROC UNIVARIATE to create the CDF and PDF plots. The HISTOGRAM statement fits and optionally overlays a nonparamwetric kernel density estimate. The CDFPLOT statement displays the empirical CDF. Here is an example:

 

proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / kernel;  /* nonparametric density estimate */
cdfplot mpg_highway;
ods select Histogram CDFPlot;
run;

You can also fit and overlay parametric distributions. PROC UNIVARIATE supports about 20 common distributions. Here is an example of fitting lognormal distribution (maximum likelihood estimation) to the same data:

proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / lognormal;  /* overlay PDF */
cdfplot   mpg_highway / lognormal;  /* overlay CDF */
ods select Histogram CDFPlot;
run;

 

Jonate_H
Quartz | Level 8

Thank you all!

by the way, how can I specify the distribution as t-distribution? without enough observations, I try to avoid normal distribution assumption.

Rick_SAS
SAS Super FREQ

Typically data are not distributed as t. The t distribution arises as the sampling distribution of statistics. See the article "Why doesn't PROC UNIVARIATE support certain common distributions?"

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2694 views
  • 2 likes
  • 3 in conversation