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
SAS Super FREQ
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);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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