%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?
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")
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.
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.