12-25-2015 12:58 AM
%macro print(libname,dslist=a b c);
%do i=1 %to 4;
proc print data=&libname..%scan(&dslist,&i);
%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;
proc print data=&libname..&a;
here it is not working without quotes?
12-25-2015 01:48 AM
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")
12-25-2015 12:57 PM
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.