sas macros

Reply
Contributor
Posts: 25

sas macros

[ Edited ]
%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

Super User
Posts: 2,505

Re: sas macros

Posted in reply to vinod4842

Please post the log using {i}.

MS office documents are best avoided.

Contributor
Posts: 25

Re: sas macros

thank you again edited

Super User
Posts: 2,505

Re: sas macros

Posted in reply to vinod4842

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;

 

Super User
Super User
Posts: 8,272

Re: sas macros

Posted in reply to vinod4842

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.

Super User
Posts: 13,920

Re: sas macros

Posted in reply to vinod4842

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.

Ask a Question
Discussion stats
  • 5 replies
  • 72 views
  • 0 likes
  • 4 in conversation