Hep with Macro

Reply
Occasional Contributor
Posts: 7

Hep with Macro

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

 

 

Super User
Posts: 8,590

Re: Hep with Macro

First of all, get your code to work without a macro. When your code runs successfully, you can then embark on making it dynamic.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
SAS Super FREQ
Posts: 470

Re: Hep with Macro

Posted in reply to KurtBremser

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

Super User
Posts: 12,148

Re: Hep with Macro

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.

 

Ask a Question
Discussion stats
  • 3 replies
  • 164 views
  • 0 likes
  • 4 in conversation