BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

%macro print(libname,dslist=a b c);
%do i=1 %to 4;
proc print data=&libname..%scan(&dslist,&i);
run;
%end;
%mend;

%print(pawan,dslist=test p1 test1 test2);

 

here if i place quotes in (dslist="test p1 test1 test2") it's not working..........in which scenerio have to place quotes and not.

 

%macro print1(libname,dslist="pawan test test1");
%do i=1 %to 4;
data _null_;
call symput('a',scan(&dslist,&i));
run;
proc print data=&libname..&a;
run;
%end;
%mend;

here it is not working without quotes?

2 REPLIES 2
Ksharp
Super User

Then put double quote into separator list and remain the validate variable name .

 

 

%macro print(libname,dslist=a b c);
%do i=1 %to 4;
 %put &libname..%scan(&dslist,&i,,kdf);
%end;
%mend;


%print(pawan,dslist=test p1 test1 test2)

%print(pawan,dslist="test p1 test1 test2")
Astounding
PROC Star

Always, always always ... when you use macro language you have to picture what the program is going to look like.

 

While KSharp gave you a correct answer, here is some of the reasoning behind it.  Picture the result of:

 

dslist="test pi test1 test2"

 

When %scan operates on this string, the first word in the list is "test and the last word is test2".  If you pictured that, you would expect to get an error for coding data=&libname.."test;

 

KSharp correctly noted that you can add doublequotes to your list of delimeters that %can uses, so that the first word woul be test instead of "test.

 

When you switch to a DATA step, the SCAN function expects to see a character string as the first parameter.  So the first word within "test pi test1 test2" would be test and not "test.  

 

I expect that you have a solution for your problem now, as well as what you need to do to avoid future problems.

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
  • 2 replies
  • 506 views
  • 0 likes
  • 3 in conversation