DATA Step, Macro, Functions and more

macro help!

Reply
N/A
Posts: 0

macro help!

Here is the complete code followed by the error message I am getting:

%macro AgeSplit(varname=);
/***Ever reported between 9 and 13***/
/***Youngest cohort (no wave E data) ***/
if (agegrup=1 and f&varname ge 1) then &varname.m=1;
else if (agegrup=1 and g&varname ge 1) then &varname.m=1;
else if (agegrup=1 and h&varname ge 1) then &varname.m=1;
/***Middle cohort***/
else if (agegrup=2 and d&varname ge 1) then &varname.m=1;
else if (agegrup=2 and e&varname ge 1) then &varname.m=1;
else if (agegrup=2 and f&varname ge 1) then &varname.m=1;
/***Oldest cohort***/
else if (agegrup=3 and b&varname ge 1) then &varname.m=1;
else if (agegrup=3 and c&varname ge 1) then &varname.m=1;
else if (agegrup=3 and d&varname ge 1) then &varname.m=1;

else &varname.m=0;
label &varname.m='1+&lbw 14-16';
%mend;
%AgeSplit(varname=lbw);
run;

Error message:
1440 %AgeSplit(varname=lbw);
NOTE: Line generated by the invoked macro "AGESPLIT".
1 if (agegrup=1 and f&varname ge 1) then &varname.m=1;
--
180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "AGESPLIT".
1 else if (agegrup=1 and g&varname ge
----
180
1 ! 1) then &varname.m=1; else if (agegrup=1 and h&varname ge 1) then &varname.m=1; else if

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "AGESPLIT".
1 else if (agegrup=1 and h&varname ge 1) then &varname.m=1; else if (agegrup=2 and

----

180
Contributor
Posts: 48

Re: macro help!

Posted in reply to deleted_user
You mix dataset statments with macro statements.
Try this:

data Your_dataset_result;
set your_dataset_source;
%AgeSplit(varname=lbw);
run;

************
Also you shoul not use ' when using macro.
label &varname.m='1+&lbw 14-16'; wont work
Try this:
label &varname.m="1+&lbw 14-16";
Ask a Question
Discussion stats
  • 1 reply
  • 119 views
  • 0 likes
  • 2 in conversation