Please help my macro code is not working
Here is the question I am being asked:
Use a single macro with two parameters to assess the correlation between mean fasting glucose and age, body composition, blood pressure and lipid concentrations
Here is my macro code
%macro mycorr(&a=, &b=);
proc corr data=PJ123 spearman;
var meanFG;
with &a;
only &b;
run;
%mend mycorr;
%mycorr(a=Age weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP);
%mycorr(a=weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP, b=age);
Here is the error code:
316 %macro mycorr(&a=, &b=);
ERROR: Invalid macro parameter name &. It should be a valid SAS identifier no longer than 32
characters.
ERROR: A dummy macro will be compiled.
317 proc corr data=PJ123 spearman;
318 var meanFG;
319 with &a;
320 only &b;
321 run;
322 %mend mycorr;
323
324 %mycorr(a=Age weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP);
-
180
WARNING: Apparent invocation of macro MYCORR not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro MYCORR not resolved.
325 %mycorr(a=weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP, b=age);
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
Start with this line instead of the one you have, see if the macro runs with that line.
%macro mycorr(a=, b=);
Thank you !
It ran with one error statement referring to the only:
%macro mycorr(a=, b=);
353 proc corr data=PJ123 spearman;
354 var meanFG;
355 with &a;
356 only &b;
357 run;
358 %mend mycorr;
359
360 %mycorr(a=Age weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP);
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE GLM used (Total process time):
real time 19:07.72
cpu time 8.87 seconds
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: Line generated by the invoked macro "MYCORR".
1 with &a; only &b; run;
----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE CORR used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
361 %mycorr(a=weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP, b=age);
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: Line generated by the invoked macro "MYCORR".
1 with &a; only &b; run;
----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE CORR used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Where's parameter b in your macro call? You defined it, but did not supply it when calling the macro.
361 %mycorr(a=weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP, b=age);
@eee100 wrote:
361 %mycorr(a=weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP, b=age);
Which is different than your previous post. Since you did not post any error, I take it that the code works now.
What is so hard to understand here?
316 %macro mycorr(&a=, &b=); ERROR: Invalid macro parameter name &. It should be a valid SAS identifier no longer than 32 characters.
valid SAS names DO NOT contain ampersands, period.
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.