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.
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.
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.
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, why only for 9.4+ ? 🙂
@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.
Cool. Never knew that, thank you 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.