BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Moksha
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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).

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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).

--
Paige Miller
Moksha
Pyrite | Level 9
Thank you very much for providing the clarification.
Kurt_Bremser
Super User

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.

 

Moksha
Pyrite | Level 9

Thank you very much for such a clear clarification.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 642 views
  • 0 likes
  • 3 in conversation