BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
m1ny
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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;

View solution in original post

3 REPLIES 3
Reeza
Super User

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.  

Reeza
Super User
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;

m1ny
Fluorite | Level 6

Thank you, Reeza, for your help.

This is my first trial of macro. This is very helpful!

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
  • 949 views
  • 1 like
  • 2 in conversation