BookmarkSubscribeRSS Feed
eee100
Calcite | Level 5

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.

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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

%macro mycorr(a=, b=);
--
Paige Miller
eee100
Calcite | Level 5

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

 

eee100
Calcite | Level 5


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

Kurt_Bremser
Super User

@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.

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1917 views
  • 1 like
  • 3 in conversation