BookmarkSubscribeRSS Feed
Max05
Obsidian | Level 7

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 🙂

11 REPLIES 11
Ksharp
Super User

Check KS Test.

 

proc npar1way data=sashelp.class plots=edfplot edf ;
class sex;
var weight;
run;
Max05
Obsidian | Level 7
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! 🙂
Ksharp
Super User

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;
Max05
Obsidian | Level 7
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!!

ballardw
Super User

@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.

Max05
Obsidian | Level 7
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.
ballardw
Super User

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;
Max05
Obsidian | Level 7

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 🙂

Ksharp
Super User

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

Rick_SAS
SAS Super FREQ

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;

 

Max05
Obsidian | Level 7

Thank you veru much for your helpful answers!! 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 5547 views
  • 3 likes
  • 4 in conversation