DATA Step, Macro, Functions and more

Cumulative Distribution Function

Reply
Contributor
Posts: 20

Cumulative Distribution Function

Goodevening, 

 

I would like to obtain only one graph with the two cumulative distribution function in order to compare them. 
However, with this code, SAS generates 2 distinct graphs: 

proc univariate data=WORK.CDF;
var AGE HEIGHT;
cdfplot ;
run;

 

What do I need to change to have both curves on one single graph in order to compare them? 

Thanks a lot in advance for your help Smiley Happy

Super User
Posts: 10,621

Re: Cumulative Distribution Function

Check KS Test.

 

proc npar1way data=sashelp.class plots=edfplot edf ;
class sex;
var weight;
run;
Contributor
Posts: 20

Cumulative Distribution Function

Hello,

First, thanks a lot for your answer. I tried to adapt your example to my case (WORK.QUERY_FOR_FINALDATABASE being my data file nd TRUEPERF and Performance_adj being the variables I want to display on the graph):

proc npar1way data=WORK.QUERY_FOR_FINALDATABASE plots=edfplot edf ;
class TRUEPERF;
var Performance_adj ;
run;

Unfortunately, I obtain the following error: ERROR: The SAS System stopped processing this step because of insufficient memory.

Do you have any idea of where my mistake is located?

thanks again! Smiley Happy
Super User
Posts: 10,621

Re: Cumulative Distribution Function

You must have a too big table to plot all these point in a graph. Try this one .

 

ods select none;
ods output EDFPlot=plot;
proc npar1way data=sashelp.class plots=edfplot edf ;
class sex;
var weight;
run;
ods select all;

proc sgplot data=plot;
step x=_x y=_edf/group=_class;
run;
Contributor
Posts: 20

Cumulative Distribution Function

I tried your code but once again, I obtain the same error (my dataset is quite large, you're right):


WARNING: You must enable ODS graphics before requesting plots.
ERROR: The SAS System stopped processing this step because of insufficient memory.

Do you have any other idea?

Thanks!!

Super User
Posts: 13,084

Re: Cumulative Distribution Function


@Max05 wrote:
I tried your code but once again, I obtain the same error (my dataset is quite large, you're right):


WARNING: You must enable ODS graphics before requesting plots.
ERROR: The SAS System stopped processing this step because of insufficient memory.

Do you have any other idea?

Thanks!!


ODS graphics on;

 

Proc <any proc with plot statements>

 

You may want to add ODS Graphics off;

afterwards so that some procs such as Proc freq don't generate plots when not wanted.

 

Also use the ODS graphics statement to control things like the height and width of the plot area if it is too small by default.

Contributor
Posts: 20

Cumulative Distribution Function

I am sorry. I adapted the code:

ods graphics on;
ods select none;
ods output EDFPlot=plot;
proc npar1way data=WORK.QUERY_FOR_FINALDATABASE plots=edfplot edf ;
class TRUEPERF;
var Performance_adj;
run;
ods select all;

proc sgplot data=plot;
step x=_x y=_edf/group=_class;
run;
ods graphics off;

But once again, I obtain the same error... :/

ERROR: The SAS System stopped processing this step because of insufficient memory.
Super User
Posts: 13,084

Re: Cumulative Distribution Function

How many levels does your TRUEPERF variable have? and Performance_adj?

 

You might try summarizing the data first and telling the procedure how many records are involved especially if you have lots of repear

proc summary data=WORK.QUERY_FOR_FINALDATABASE  nway;
   class TRUEPERF Performance_adj;
   output out=work.summarized;
run;
/* which adds _freq_ with the count of combinations of the CLASS variables*/
proc npar1way data=WORK.summarized plots=edfplot edf ;
   class TRUEPERF;
   var Performance_adj;
   freq _freq_;
run;
Contributor
Posts: 20

Re: Cumulative Distribution Function

Goodevening, 

I have once again one problem with this procedure that I cannot solve. 

 

My dataset is really simple and not big (2 columns and 100 lines) with this structure

 

ActualReturn                         BootstrapReturn

-2.18                                         -2.08

-2.06                                         -2.01

...                                                ...

 

I can plot both on seperate graphs without any problems with the following code: 

 

title 'Cumulative Distribution Function of Breaking Strength';
ods graphics on;
proc univariate data=work.cdf noprint;
cdf ActualReturn BootstrapReturn / overlay;
run;

 

But when I use the following code to plot both on the same one, nothing appears on the graph even though I have no error in my log. 

The other codes proposed do not work neither...

 

ods graphics on;
proc summary data=WORK.cdf nway;
class ActualReturn BootstrapReturn;
output out=work.summarized;
run;
/* which adds _freq_ with the count of combinations of the CLASS variables*/
proc npar1way data=WORK.summarized plots=edfplot edf ;
class ActualReturn;
var BootstrapReturn;
freq _freq_;
run;

 

Do you have any idea of the reason which could explain that? Thanks Smiley Happy

Super User
Posts: 10,621

Re: Cumulative Distribution Function

Maybe you could manually calculate CDF and plot both in a graph .

 

data Exp;
set A nobs=nobs;
v = (_N_ - 0.375) / (nobs + 0.25); /* 2 */
q = quantile("Exponential", v, 2); /* 3 */
run;

Here is  the blog about it written by @Rick_SAS

https://blogs.sas.com/content/iml/2011/10/28/modeling-the-distribution-of-data-create-a-qq-plot.html

SAS Super FREQ
Posts: 4,124

Re: Cumulative Distribution Function

[ Edited ]

See the article "Comparative histograms in SAS", which shows how to use the CLASS statement in PROC UNIVARIATE to overlay the plots. In this case, you want PROC UNIVARIATE to overlay the CDFPLOT.

 

The steps are:

1. Convert the data from wide to long.

2. Use PROC UNIVARIATE and the OVERLAY option on the CDFPLOT statement to overlay the CDFPlots

 

The variables should be on the same (or similar scale).

 

data Have;
set Sashelp.Class;
length varName $20;
ObsNum = _N_;
varName = "Age";    Value = Age;    output; /* put VAR1 on this line */
varName = "Height"; Value = Height; output; /* put VAR2 on this line */
run;

proc univariate data=Have;
   class varName;
   var Value;
   cdfplot Value/ overlay;
run;

 

Contributor
Posts: 20

Re: Cumulative Distribution Function

Thank you veru much for your helpful answers!! Smiley Happy

Ask a Question
Discussion stats
  • 11 replies
  • 195 views
  • 3 likes
  • 4 in conversation