turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- How to output Proc Means output to a macro variabl...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-06-2009 02:51 AM

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;

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

08-06-2009 03:51 AM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

08-10-2009 10:58 AM

I don't think there is a more "code efficient" way than using call symput. This is the way I do it.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

08-10-2009 01:17 PM

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;

data _null_;

set tmp_median_aaa;

call symputx('tmp_median_aaa', tmp_median_aaa);

run;