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

Hi all,

 

Following is my code:

I need to calculate the mean of default_flag and median of P_1, and later create sgplot.

By using proc means, I am only able to get the mean values. Is there any way I can get mean of one and median of other in a single proc or other alternative.

 

proc means data=temp nway mean median;
     class snap_qtr qtr;
     var default_flag P_1;
     output out=data1 ;
run;
ods graphics on /  reset width=4in height=3in outputfmt=gif imagemap=on border=off;
title "SGPLOT Output";
ods layout start;
proc sgplot data=data1 ;

           series x=qtr y=default_flag/ legendlabel="Default Rate" markers lineattrs=(thickness=2);
           series x=qtr y=P_1/y2axis legendlabel="P rate" markers lineattrs=(thickness=2);
           xaxis display=(noline) interval=year grid  label="Time Period";
           yaxis display=(noline) grid  label="Default Rate" ;
           y2axis label="P rate";
run;
ods layout end;
title; 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Output out = want mean(variable1) = mean_var1 median(variable2) = median_var2;

 

You need to change the OUTPUT statement and you can refer to variables within parentheses to limit the output to the variables of interest. You may need to drop the VAR statement. 

View solution in original post

6 REPLIES 6
Reeza
Super User

Output out = want mean(variable1) = mean_var1 median(variable2) = median_var2;

 

You need to change the OUTPUT statement and you can refer to variables within parentheses to limit the output to the variables of interest. You may need to drop the VAR statement. 

PeterClemmensen
Tourmaline | Level 20

Or use PROC SQL and do something like this

 

proc sql;
   create table data1 as
   select mean(default_flag) as mean_default_flag
         ,median(default_flag) as median_default_flag
         ,mean(P1) as mean_P1
         ,median(P1) as median_P1
   from temp
   group by snap_qtr, qtr;
quit;
Reeza
Super User

@PeterClemmensen The median function doesn't exist in PROC SQL for SAS 9.3 and lower versions.

Or at least not how you'd expect it to work, it calculates the median for the row, which for a single value is the single value. 

 

http://support.sas.com/kb/12/133.html

 

In 9.4 it calculates the median the same way PROC MEANS does, though I'm not sure what method it uses so you could potentially get different answers still if PCTLDEF was specified. 

http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n1qnc9bddfvhzqn105kqi...

 

 

 

 

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
  • 6 replies
  • 4549 views
  • 1 like
  • 3 in conversation