Dear SAS Base Gurus, I am trying to work something out which I am sure SAS can do but not sure how to continue with incorporating loop within macro. Herewith the background as follows: Got this code (IMReplicateForum.sas) from mr.google; /*HAD THIS MACRO BELOW FROM SAS MASTER SIFU VIA GOOGLE*/
%macro intmed(dset, var);
proc means data=&dset. median noprint;
var &var.;
output out=outmed median=median;
run;
data _null_;
set outmed;
call symput("Median", median);
run;
data transform;
set &dset. end=last;
retain nl ne ng 0;
median = &median.*1;
if &var. < median then nl = nl+1;
if &var. = median then ne = ne+1;
if &var. > median then ng = ng+1;
if last then do;
if ne ne 0 then do;
intmed = median + (ng-nl)/(2*ne);
end;
else if ne = 0 then do;
intmed = median;
end;
output;
end;
label median = "Median"
intmed = "Interpolated Median";
keep median intmed;
run;
proc print data = transform label noobs;
title "Value for Median and Interpolated Median";
var median intmed;
run;
title "";
%mend;
data Survey1 (keep=Question1AreUSatisfy);
set Survey;
if Question1AreUSatisfy; /*GET RID NULL/BLANK*/
if ProgramID eq "MATH101";
run;
%intmed (Survey1, Question1AreUSatisfy);
*AT PRESENT THE MACRO JUST SHOWIN UP (OUTPUT) INTERPOLATED MEDIAN (IM) FIGURES ONE AT THE TIME BASED ON DATA SET.
*AS I AM SAS NEWBIE, I AM LOOKING ENLIGHTENMENT HOW TO DO THIS RATHER THAN 'MANUALLY' SUBSET DATA & POPULATE "IM" FIGURES. The macro run perfectly to produce Interpolated Median figures from Survey dataset (survey.sas7bdat) attached. The macro generate Interpolated Median (IM) figures in output one at a time based on unique ProgramID (Primary Key) subset data. What I try to achieve populate IM figures automatically in the list by add in new IM field consist figure from macro (e.g.: rather than hard coding IM figure one at a time back into dataset). As I am newbie with limited knowledge of SAS macro and loop, any enlightenment will be appreciated. Thanks in advance.
... View more