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.

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
  • 4 replies
  • 970 views
  • 1 like
  • 3 in conversation