HELP WITH MACRO

Reply
Occasional Contributor
Posts: 7

HELP WITH MACRO

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

  1. Obtain unadjusted correlations between mean fasting plasma glucose and age, weight, weight at age of 20, percent weight change, waist to hip ratio, BMI, HDL cholesterol, total cholesterol, the ratio of total to HDL cholesterol (as a continuous variable), systolic blood pressure and diastolic blood pressure.
  2. Obtain age-adjusted correlation coefficients for the above-mentioned correlation tests (except for the correlation between mean fasting plasma glucose and age)

 

 

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.

 

Respected Advisor
Posts: 2,155

Re: HELP WITH MACRO

Start with this line instead of the one you have, see if the macro runs with that line.

%macro mycorr(a=, b=);
--
Paige Miller
Occasional Contributor
Posts: 7

Re: HELP WITH MACRO

Posted in reply to PaigeMiller

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

 

Super User
Posts: 8,589

Re: HELP WITH MACRO

Where's parameter b in your macro call? You defined it, but did not supply it when calling the macro.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 7

Re: HELP WITH MACRO

Posted in reply to KurtBremser


361 %mycorr(a=weight20 WTPCT WHR BMI HDL CHOL TCHDL SBP DBP, b=age);

Super User
Posts: 8,589

Re: HELP WITH MACRO


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 8,589

Re: HELP WITH MACRO

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 6 replies
  • 176 views
  • 1 like
  • 3 in conversation