BookmarkSubscribeRSS Feed
eee100
Calcite | Level 5

Help with macro coding. I am not sure where to place the referent code. 

 

Here is the question:

 

Use linear regression models (PROC REG) to assess correlates of mean fasting plasma glucose concentrations.

  1. Note that dummy variables should be created for categorical variables with more than two levels. Create dummy variables for BMIcat, NKIDS, and TCHDL_Q using arrays.  Use the appropriate procedure to check the dummy variables created against the original categorical variables.
  2. Using a macro code with one parameter, construct separate linear regression models with mean fasting plasma glucose as the dependent (outcome) variables and each of the following (separate models for each) as the independent variable:
    1. BMI
    2. BMI categories using the Underweight / normal weight category as the referent
  • Percent weight change
  1. Menopausal status
  2. Number of kids (using “No children” as the referent category)
  3. Quartiles of the ratio of total to HDL cholesterol (using the 1st quartile as the referent category).

 

Here is  my code:

 

%macro regress(p=);
proc reg data=PJ123;
model meanFG (event="1") = &p;
run;
%mend regress;

%regress(p=BMI);
%regress(p=BMIcat (ref="dBMIcat1"));
%regress(p=WTPCT);
%regress(p=MNP);
%regress(p=NKIDS)(ref="dNKIDS1"));
%regress(p=TCHDL_q (ref="dTCHDL1"));

 

Here is the error:

 

%macro regress(p=);
381 proc reg data=PJ123;
382 model meanFG (event="1") = &p;
383 run;
384 %mend regress;
385
386 %regress(p=BMI);
NOTE: Line generated by the invoked macro "REGRESS".
1 proc reg data=PJ123; model meanFG
1 ! (event="1") = &p; run;
-
22
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 "REGRESS".
1 (event="1") = &p; run;
-
76
NOTE: The previous statement has been deleted.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, =, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.07 seconds
cpu time 0.03 seconds


387 %regress(p=BMIcat (ref="dBMIcat1"));
NOTE: Line generated by the invoked macro "REGRESS".
1 proc reg data=PJ123; model meanFG
1 ! (event="1") = &p; run;
-
22
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 "REGRESS".
1 (event="1") = &p; run;
-
76
NOTE: The previous statement has been deleted.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, =, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.06 seconds
cpu time 0.00 seconds


388 %regress(p=WTPCT);
NOTE: Line generated by the invoked macro "REGRESS".
1 proc reg data=PJ123; model meanFG
1 ! (event="1") = &p; run;
-
22
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 "REGRESS".
1 (event="1") = &p; run;
-
76
NOTE: The previous statement has been deleted.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, =, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds


389 %regress(p=MNP);
NOTE: Line generated by the invoked macro "REGRESS".
1 proc reg data=PJ123; model meanFG
1 ! (event="1") = &p; run;
-
22
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 "REGRESS".
1 (event="1") = &p; run;
-
76
NOTE: The previous statement has been deleted.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, =, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.06 seconds
cpu time 0.06 seconds


390 %regress(p=NKIDS)(ref="dNKIDS1"));
NOTE: Line generated by the invoked macro "REGRESS".
1 proc reg data=PJ123; model meanFG
1 ! (event="1") = &p; run;
-
22
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 "REGRESS".
1 (event="1") = &p; run;
-
76
NOTE: The previous statement has been deleted.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, =, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds


180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN
where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
391 %regress(p=TCHDL_q (ref="dTCHDL1"));
NOTE: Line generated by the invoked macro "REGRESS".
1 proc reg data=PJ123; model meanFG
1 ! (event="1") = &p; run;
-
22
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 "REGRESS".
1 (event="1") = &p; run;
-
76
NOTE: The previous statement has been deleted.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, =, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds

 

 

3 REPLIES 3
WarrenKuhfeld
Rhodochrosite | Level 12

@Kurt_Bremser is right.  Furthermore, look at the documentation.  You can't use syntax from multiple procedures and statements interchangeably.  Documentation is free on the web and searchable via Google.

ballardw
Super User

Best is to post LOG results into a code box opened with the forum {I} menu icon. This will preserve formatting of the log errors.

Most of the error messages will place an underscore character under the position in a line of code indicating where SAS encountered the error.

The main message windows reformats text removing that clue.

 

And yes. Get an example to work for anything before attempting macro code.

 

Hint: Proc reg is one of the regression procedures that actually supports multiple MODEL statements. Use Label: Model so the model name indicated in the label text is displayed to indicate which model statement is generating which output. Be very careful with correct syntax though.

Hint: Proc reg wants a quit; after the final run to indicate the procedure is finished. This is a by product of the ability to run models interactively or run group processing that allows multiple models.

 

Hint: Passing quotes in macro parameters is very  problematic at best and a problem causer at worst.

 

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
  • 3 replies
  • 433 views
  • 0 likes
  • 4 in conversation