First, realize that you will eventually need to deal with realistic questions. What should happen with ROI:
Is exactly equal to the median?
Has a missing value?
Here is an approach that extends tools that you already know, to get the result:
proc summary data=have;
var roi;
output out=medians (keep=roi_median) median=roi_median;
run;
That gives you the median in a data set, which can be used in a subsequent step.:
data want;
set have;
if _n_=1 then set medians;
roi_group = roi >= roi_median;
drop roi_median; run;
Note that the logic can easily be expanded to compute/group for more than one variable, without increasing the number of steps. For example, you could begin with:
proc summary data=have;
var roi margin turnover;
output out=medians (keep=roi_median margin_median turnover_median) median=roi_median margin_median turnover_median;
run;
Also note that the assignment statement that computes roi_group could have been accomplished with IF/THEN statements, but would take more code:
if roi >= roi_median then roi_group=1;
else roi_group = 0;
But the assignment statement shown above accomplishes the same with a shorter program.
... View more