Not applicable
Posts: 0

# How to use macro to store the value of median for a variable? Options

Hi Guys:

My overall objective is: From the dataset, I want to compute the
median of variable A, and use this value,(say median) to create a
dummy variable, D, where D=1 if A_i>=median and 0 otherwise.(i stands
for the ith observation of variable A).

How to do that using macro because I need to create this kind of dummy
variables for many different datasets. Thanks in advance!!!

Richard
SAS Super FREQ
Posts: 9,365

## Re: How to use macro to store the value of median for a variable? Options

Hi:
This is not really an ODS or BASE Reporting procedure (PRINT, REPORT, TABULATE) question. Your best bet for help with this question is to search for user group papers on applications for macro variables or to contact Tech Support.
For example, here are a few user group papers that might be relevant:
http://www2.sas.com/proceedings/sugi24/Coders/p087-24.pdf
http://www2.sas.com/proceedings/sugi28/090-28.pdf
http://ndc.mayo.edu/mayo/research/biostat/sasmacros.cfm

cynthia
Frequent Contributor
Posts: 93

## Re: How to use macro to store the value of median for a variable? Options

Try this:
```
%macro flag_median(var=,inmem=,outmem=);
proc summary data=&inmem nway missing;
var &var;
output out=median(drop=_type_) median=;
run;
proc sql noprint;
select &var,_freq_ into :median separated by ' ',:count separated by ' '
from median;
quit;
proc delete data=median;
run;
%put Median for &count observations of variable <&var> is &median;
data &outmem;
set &inmem;
&var._median = &median;
flag_&var = (&var => &var._median);
run;
proc print data=&outmem;
run;
%mend  flag_median;
%flag_median(var=Height,inmem=sashelp.class,outmem=outstuff);
```
Not applicable
Posts: 0

## Re: How to use macro to store the value of median for a variable? Options

Thanks guys!
Discussion stats
• 3 replies
• 537 views
• 0 likes
• 3 in conversation