DATA Step, Macro, Functions and more

Macro error: value obtained from proc means in data step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Macro error: value obtained from proc means in data step

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


Accepted Solutions
Solution
‎02-09-2016 01:53 PM
Super User
Posts: 19,877

Re: Macro error: value obtained from proc means in data step

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


All Replies
Super User
Posts: 19,877

Re: Macro error: value obtained from proc means in data step

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.  

Solution
‎02-09-2016 01:53 PM
Super User
Posts: 19,877

Re: Macro error: value obtained from proc means in data step

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;

Occasional Contributor
Posts: 7

Re: Macro error: value obtained from proc means in data step

Thank you, Reeza, for your help.

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 268 views
  • 1 like
  • 2 in conversation