Help my macro code is not working
Here is the question I am asked:
. Assess mean differences in percent weight change by categories of BMI and by the number of children using regression models. The dependent (outcome) variable each time should be percent weight change. The main independent variable would be either BMI categories or number of children. Use one macro with two parameters to complete this question.
Here is my code:
%macro myglm(class=, indep=);
proc glm data=&PJ123;
class &class;
model WTPCT = &class &indep;
means &class;
lsmeans &class / adjust=bon stderr pdiff;
run;
%mend myglm;
%myglm (class=BMICAT);
%myglm (class=BMICAT, indep=Age);
%myglm (class=BMICAT MNP, indep=Age);
%myglm (class=NKIDS);
%myglm (class=NKIDS, indep=Age);
%myglm (class=NKIDS BMI MNP, indep=Age);
Here is my error message:
326
327 %macro myglm(class=, indep=);
328 proc glm data=&PJ123;
329 class &class;
330 model WTPCT = &class &indep;
331 means &class;
332 lsmeans &class / adjust=bon stderr pdiff;
333 run;
334 %mend myglm;
335
336 %myglm (class=BMICAT);
NOTE: Line generated by the invoked macro "MYGLM".
1 proc glm data=&PJ123; class &class; model WTPCT = &class &indep; means &class
-
22
200
1 ! ; lsmeans &class / adjust=bon stderr pdiff; run;
WARNING: Apparent symbolic reference PJ123 not resolved.
NOTE: Data file WORK.PJ123.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: The previous statement has been deleted.
ERROR: Only CLASS variables allowed in this effect.
NOTE: The previous statement has been deleted.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: A MODEL statement must be given.
337 %myglm (class=BMICAT, indep=Age);
NOTE: PROCEDURE GLM used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
NOTE: Line generated by the invoked macro "MYGLM".
1 proc glm data=&PJ123; class &class; model WTPCT = &class &indep; means &class;
-
22
200
1 ! lsmeans &class / adjust=bon stderr pdiff; run;
WARNING: Apparent symbolic reference PJ123 not resolved.
NOTE: Data file WORK.PJ123.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: The previous statement has been deleted.
ERROR: Only CLASS variables allowed in this effect.
NOTE: The previous statement has been deleted.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: A MODEL statement must be given.
338 %myglm (class=BMICAT MNP, indep=Age);
NOTE: PROCEDURE GLM used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Line generated by the invoked macro "MYGLM".
1 proc glm data=&PJ123; class &class; model WTPCT = &class &indep; means &class;
-
22
200
1 ! lsmeans &class / adjust=bon stderr pdiff; run;
WARNING: Apparent symbolic reference PJ123 not resolved.
NOTE: Data file WORK.PJ123.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: The previous statement has been deleted.
ERROR: Only CLASS variables allowed in this effect.
NOTE: The previous statement has been deleted.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: A MODEL statement must be given.
339 %myglm (class=NKIDS);
NOTE: PROCEDURE GLM used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Line generated by the invoked macro "MYGLM".
1 proc glm data=&PJ123; class &class; model WTPCT = &class &indep; means &class;
-
22
200
1 ! lsmeans &class / adjust=bon stderr pdiff; run;
WARNING: Apparent symbolic reference PJ123 not resolved.
NOTE: Data file WORK.PJ123.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: The previous statement has been deleted.
ERROR: Only CLASS variables allowed in this effect.
NOTE: The previous statement has been deleted.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: A MODEL statement must be given.
340 %myglm (class=NKIDS, indep=Age);
NOTE: PROCEDURE GLM used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Line generated by the invoked macro "MYGLM".
1 proc glm data=&PJ123; class &class; model WTPCT = &class &indep; means &class;
-
22
200
1 ! lsmeans &class / adjust=bon stderr pdiff; run;
WARNING: Apparent symbolic reference PJ123 not resolved.
NOTE: Data file WORK.PJ123.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: The previous statement has been deleted.
ERROR: Only CLASS variables allowed in this effect.
NOTE: The previous statement has been deleted.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: A MODEL statement must be given.
341 %myglm (class=NKIDS BMI MNP, indep=Age);
NOTE: PROCEDURE GLM used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Line generated by the invoked macro "MYGLM".
1 proc glm data=&PJ123; class &class; model WTPCT = &class &indep; means &class;
-
22
200
1 ! lsmeans &class / adjust=bon stderr pdiff; run;
WARNING: Apparent symbolic reference PJ123 not resolved.
NOTE: Data file WORK.PJ123.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: The previous statement has been deleted.
ERROR: Only CLASS variables allowed in this effect.
NOTE: The previous statement has been deleted.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: A MODEL statement must be given.
WARNING: Apparent symbolic reference PJ123 not resolved.
You never defined macro variable PJ123
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.