BookmarkSubscribeRSS Feed
vinod4842
Fluorite | Level 6
%macro vars(first=1,last=);
   %global gfirst glast;
   %let gfirst=&first;
   %let glast=&last;
   var test&first-test&last;
%mend vars;
%put &gfirst;
proc print;
   %vars(last=50)
   title "Analysis of Tests &gfirst-&glast";
run;
PROC PRINT;
   VAR TEST1-TEST50;
   TITLE "Analysis of Tests 1-50";
RUN;

 

 

Capture.PNG

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

Please post the log using {i}.

MS office documents are best avoided.

vinod4842
Fluorite | Level 6

thank you again edited

ChrisNZ
Tourmaline | Level 20

As @Tom said, add data=

Also, your macro would probably be more useful like this:

%macro vars(first=1,last=);
   var test&first - test&last;
   title "Analysis of Tests &first-&last";
%mend vars;

proc print;
   %vars(last=50)
run;

 

Tom
Super User Tom
Super User

The error messages seems pretty clear.

You need to tell SAS what dataset you want it to print.

 

It has nothing to do with the macro.

ballardw
Super User

When you use syntax like:

 

proc print;

run;

 

Then Proc Print, or other Procedure,  will assume that you want to use the last created data set as input.

If your current session has not created any data set then you get that error.

 

While SAS is helpful about making guesses for things like the last data set it is very poor practice to rely on those guesses.

 

I would also suggest passing a "stem" value for the variable list to make the macro a little more useful

%macro vars(stem=test,first=1,last=);
   %global gfirst glast;
   %let gfirst=&first;
   %let glast=&last;
   var &stem.&first-&stem.&last;
%mend vars;

Then you could create a list of any varaibles that start with a common name portion.

 

But the data set you attempt to print or process has to have those variables in it and really should be named.

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 5 replies
  • 901 views
  • 0 likes
  • 4 in conversation