%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
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.
And
Options nomprint nosymbolgen; to turn it off.
You can use the MPRINT SYMBOLGEN individually.
Semi-colons are very important in SAS syntax.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.