Hi All,
I am trying the code execute the code given in
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1lhhti7fjxgb1n1fuiubqk11h4d.htm
But, It's not working.
Please, help me to understand why this error is coming and how to rectify it.
These programs given at the above SAS site say that it will give some output but instead of that I am getting errors.
Code is:
%macro vars(first=1,last=);
%global gfirst glast;
%let gfirst=&first;
%let glast=&last;
var test&first-test&last;
%mend vars;
proc print;
%vars(last=50)
title "Analysis of Tests &gfirst-&glast";
run;
In the log:
26 options mprint;
27 %macro vars(first=1,last=);
28 %global gfirst glast;
29 %let gfirst=&first;
30 %let glast=&last;
31 var test&first-test&last;
32 %mend vars;
33 proc print;
ERROR: There is not a default input data set (_LAST_ is _NULL_).
34 %vars(last=50)
MPRINT(VARS): var test1-test50;
35 title "Analysis of Tests &gfirst-&glast";
36 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Similarly, the program given in
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0i4icf2nv7wu7n1lm4wf1epykfh.htm#p06...
is also not working.
The code from this link is:
%macro namels3(name,number);
%local n;
%global g_number;
%let g_number=&number;
%do n=1 %to &number;
&name&n
%end;
%mend namels3;
%let n=North State Industries;
proc print;
var %namels3(dept,5);
title "Quarterly Report for &n";
footnote "Survey of &g_number Departments";
run;
In the log:
37 %macro namels3(name,number);
38 %local n;
39 %global g_number;
40 %let g_number=&number;
41 %do n=1 %to &number;
42 &name&n
43 %end;
44 %mend namels3;
45 %let n=North State Industries;
46
47 proc print;
ERROR: There is not a default input data set (_LAST_ is _NULL_).
48 var %namels3(dept,5);
MPRINT(NAMELS3): dept1 dept2 dept3 dept4 dept5
49 title "Quarterly Report for &n";
50 footnote "Survey of &g_number Departments";
51 run;
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
This error has nothing to do with GLOBAL macro variables.
You have to tell PROC PRINT what data set to use.
proc print data=somedatasetname;
If you don't use the DATA= option, PROC PRINT tries to use the last data set created, but that doesn't apply here, there is no "last data set created" in this SAS session, there have been no data sets created in this session (that's what the error message is saying).
This error has nothing to do with GLOBAL macro variables.
You have to tell PROC PRINT what data set to use.
proc print data=somedatasetname;
If you don't use the DATA= option, PROC PRINT tries to use the last data set created, but that doesn't apply here, there is no "last data set created" in this SAS session, there have been no data sets created in this session (that's what the error message is saying).
When you execute a PROC statement without a DATA= option, SAS tries to use the last created dataset; if you did not create a dataset in your SAS session, the system optiion _LAST_ is _NULL_, and you'll get this ERROR.
The examples are there to show how the macro processor creates code; actual function of the created code is not necessary.
Thank you very much for such a clear clarification.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.