BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
1 REPLY 1
SAS_user
Calcite | Level 5
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";

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 951 views
  • 0 likes
  • 2 in conversation