hello,
I am trying to classify a variable (afb_geo) into two group (lower than median vs. higher than median).
I heard sas macro can do this; so, I tried. But there was error.
664 data positive_s;
665 retain RHSP_ID afb_geo ln_afb_geo afb1 age1 date1 afb2 age2 date2 afb3 age3 date3;
666 format hiv_confirm date1-date3 mmddyy10.;
667 set positive_s;
668 call("positive_s", median_afb)=median_afb;
ERROR: Undeclared array referenced: call.
ERROR: Variable call has not been declared as an array.
669 if ln_afb_geo>=median_afb then af_class=2;
670 else af_class=1;
671 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.POSITIVE_S may be incomplete. When this step was stopped there were 0
observations and 33 variables.
WARNING: Data set WORK.POSITIVE_S was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
672 data positive_s;
673 retain RHSP_ID afb_geo ln_afb_geo afb1 age1 date1 afb2 age2 date2 afb3 age3 date3;
674 format hiv_confirm date1-date3 mmddyy10.;
675 set positive_s;
676 median_afb=call("positive_s", median_afb);
----
68
ERROR 68-185: The function CALL is unknown, or cannot be accessed.
677 if ln_afb_geo>=median_afb then af_class=2;
678 else af_class=1;
679 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.POSITIVE_S may be incomplete. When this step was stopped there were 0
observations and 33 variables.
WARNING: Data set WORK.POSITIVE_S was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
proc means data=positive_s median;
var ln_afb_geo;
output out=median_dataset med(ln_afb_geo)=median;
run;
proc sql noprint;
select median into :median_value
from median_dataset;
quit;
%put &median_value;
data positive_s_cat;
set positive_s_cat;
if ln_afb_geo > &median_value then af_class=2;
else af_class=1;
run;
You can do this, but your code is incorrect. CALL isn't a valid function, so I"m not sure what your trying to do there.
Steps in this would be:
1. Calculate median (proc means)
2. Assign to macro variables
3. Use in either SQL or data step to categorize variables.
If you have SAS 9.4 this could be done in one step in proc sql.
proc means data=positive_s median;
var ln_afb_geo;
output out=median_dataset med(ln_afb_geo)=median;
run;
proc sql noprint;
select median into :median_value
from median_dataset;
quit;
%put &median_value;
data positive_s_cat;
set positive_s_cat;
if ln_afb_geo > &median_value then af_class=2;
else af_class=1;
run;
Thank you, Reeza, for your help.
This is my first trial of macro. This is very helpful!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.