BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Cynthia_sas
Diamond | Level 26
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
advoss
Quartz | Level 8
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);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2638 views
  • 0 likes
  • 3 in conversation