%macro ab(lib,ds);
%do i=1 %to 3;
%let x=%scan("&ds",&i,',');
proc print data=&lib..&x;
run;
%end;
%mend;
%ab(test ,test1 )
%macro ab;
proc sql;
select distinct memname into:a separated by ',' from dictionary.columns where libname="PAWAN" and memname like"A%";
%let x=&sqlobs;
quit;
%do i=1 %to x;
%let x=%scan("&a",&i,'i');
proc print data=pawan..&x;
run;
%end;
%mend;
%ab;
in the first macro i'm getting error but in the second it is working fine??
why %scan is not working in the first macro???what's the logic
What is your error?
Different issue could happen when running your first macro
Try this
%macro ab(lib,ds);
%let c=%sysfunc(countw(&ds));
%do i=1 %to &c;
%let x=%scan(&ds,&i,',');
%put &y;
proc print data=&lib..&x;
run;
%end;
%mend;
This shold works if you do not use double quote with ds when calling your macro
when i'm passing values in a macro by "into" using proc sql then we are enclosing that macro variable in double quotes and normally v r not doing it .why so??
like here
%macro ab;
proc sql;
select distinct memname into:a separated by ',' from dictionary.columns where libname="PAWAN" and memname like"A%";
%let x=&sqlobs;
quit;
%do i=1 %to x;
%let x=%scan("&a",&i,'i');
proc print data=pawan..&x;
run;
%end;
%mend;
%ab;
i'm enclosing &ds in double quotes and it's working fine then why not in first scenerio as we are using the same %scan function in both???
Clearly, you are not showing us your real programs. Your second program that you claim is working contains at least two errors. So until you show us your real programs, nobody can debug them.
Your first program should not be using double quotes. You would expect this to generate an error:
proc print data=lib."cars;
If you were to turn on the MPRINT option, you could see that this is the code being generated.
Good luck.
Although your secnd macro _as it is _ may give the output. But, if you checked the log you will find error too.
can u plz tell that while using %scan when we have to keep our macro variable within double quotes and when not?
%macro ab(ds);
%do i=1 %to 3;
%let x=%scan("&ds",&i,',');
proc print data=&lib..&x;
run;
%end;
%mend;
%ab(test ,test1,test2 );
it should work but it's not working??
Yesterday you posted this same macro and you were given options on how to correct it.
It doesn't appear you've made any of the changes suggested.
Again, you are passing more parameters to the macro than you have defined.
%macro ab(lib,ds);
%do i=1 %to 3;
%let x=%scan(&ds,&i,%str(,));
proc print data=&lib..&x;
run;
%end;
%mend;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.