BookmarkSubscribeRSS Feed
Prasad84
Fluorite | Level 6

%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

4 REPLIES 4
ballardw
Super User

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.

Prasad84
Fluorite | Level 6
Got it.Thanks a lot
ballardw
Super User

And

Options nomprint nosymbolgen; to turn it off.

You can use the MPRINT SYMBOLGEN individually.

Tom
Super User Tom
Super User

Semi-colons are very important in SAS syntax.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1720 views
  • 1 like
  • 3 in conversation