BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I want to generate the median of a variable, and I understand that PROC SQL is only capable of calc median horizontally and not vertically. Now my question is, if I use proc means, is there a way to output the median to a macro variable? I'm hoping to find a more code-efficient way instead of having to write another datastep to call symput to a macro variable.

my current code:
proc means data=tmp_aaa noprint;
var pvol;
output out=tmp_median_aaa median=tmp_median_aaa;
;
run;

data tmp_median_aaa;
set tmp_median_aaa;
call symput('tmp_median_aaa', tmp_median_aaa);
run;
3 REPLIES 3
DanielSantos
Barite | Level 11
Hello.

From my knowledge this is the most efficient way of doing this.

You could use the SELECT INTO: feature of PROC SQL to populate a macro var after doing the necessary aggregation. But as you already pointed out, there is no support for MEDIAN(X) summary functions (vertically), just the common datastep MEDIAN function (horizontally).

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
Paige
Quartz | Level 8
I don't think there is a more "code efficient" way than using call symput. This is the way I do it.
deleted_user
Not applicable
I agree with the other posters. A very (very) slight improvement would be to avoid outputting the median data set again, as in:

data _null_;
set tmp_median_aaa;
call symputx('tmp_median_aaa', tmp_median_aaa);
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 6686 views
  • 0 likes
  • 3 in conversation