Macros

Reply
Occasional Contributor
Posts: 8

Macros

%macro cols1;
name age;
%mend;
%macro cols2;
height weight
%mend;

 

 

1.proc print data=sashelp.class;
var %cols2 %cols1 ;
run;

 

2.proc print data=sashelp.class;
var %cols1 %cols2 ;
run;

 

 I am getting result when i used first proc print, Error for second one.Please any one explain.

 

Thanks

Super User
Posts: 13,498

Re: Macros

First introduce a basic diagnostic tool: Options mprint symbolgen;

If you run that code before something using macros the resolution of the macros (and the associated error messages) appear more like non-macro code in the log.

 

Generally it helps to show the code and the error messages from the log. Copy from the Log and paste into a code box opened using the forum {I} menu icon.

 

Note that the macro Cols1 has ; as part of the value with the variables and Cols2 does not.

2709
2710  %macro cols1;
2711  name age;
2712  %mend;
NOTE: The macro COLS1 completed compilation without errors.
      5 instructions 60 bytes.
2713  %macro cols2;
2714  height weight
2715  %mend;
NOTE: The macro COLS2 completed compilation without errors.
      5 instructions 64 bytes.
2716
2717  options mprint symbolgen;
2718
2719  proc print data=sashelp.class;
NOTE: Writing HTML Body file: sashtml5.htm
2720  var %cols2 %cols1 ;
MPRINT(COLS2):   height weight
MPRINT(COLS1):   name age;
2721  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.85 seconds
      cpu time            0.48 seconds


2722
2723  proc print data=sashelp.class;
2724  var %cols1 %cols2 ;
MPRINT(COLS1):   name age;
NOTE: Line generated by the invoked macro "COLS2".
1      height weight
       ------
       180
MPRINT(COLS2):   height
ERROR 180-322: Statement is not valid or it is used out of proper order.
2725  run;
MPRINT(COLS2):   weight

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


So you see in the second Proc print that the var statement looks like

 

var name age; height weight;

and the first ; ends the VAR so height is treated as an unknown option for proc print and throws the error.

Occasional Contributor
Posts: 8

Re: Macros

Got it.Thanks a lot
Super User
Posts: 13,498

Re: Macros

And

Options nomprint nosymbolgen; to turn it off.

You can use the MPRINT SYMBOLGEN individually.

Super User
Super User
Posts: 8,069

Re: Macros

Semi-colons are very important in SAS syntax.

Ask a Question
Discussion stats
  • 4 replies
  • 158 views
  • 1 like
  • 3 in conversation