HELP with macro coding

Reply
Occasional Contributor
Posts: 7

HELP with macro coding

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.

  1. Test the mean difference in percent weight change by BMI category in three models:
    1. Unadjusted (Model 1)
    2. Adjusted for age (Model 2)
    3. Adjusted for age and menopause status (Model 3)
  2. Test the mean difference in percent weight change by number of children (categorical variable) in three models:
  3. Unadjusted
  4. Adjusted for age
  5. Adjusted for age, BMI and menopause status
  6. From the above analysis, complete Table 3, making sure you report adjusted means when more than a single variable is included in the model (Type 3 SS). Also make sure you report p-values adjusted for multiple comparisons for categorical variables with more than two levels (use the Bonferroni correction for multiple comparisons).

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.

Super User
Posts: 9,933

Re: HELP with macro coding

WARNING: Apparent symbolic reference PJ123 not resolved.

You never defined macro variable PJ123

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 1 reply
  • 168 views
  • 0 likes
  • 2 in conversation