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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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