BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

 

 

 

%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

9 REPLIES 9
mohamed_zaki
Barite | Level 11

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

pawandh
Fluorite | Level 6

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??

 

 

pawandh
Fluorite | Level 6

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???

Astounding
PROC Star

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.

mohamed_zaki
Barite | Level 11

Although your secnd macro _as it is _ may give the output. But, if you checked the log you will find error too.

pawandh
Fluorite | Level 6

can u plz tell that while using %scan when we have to keep our macro variable within double quotes and when not?

pawandh
Fluorite | Level 6

%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??

 

JoshB
Quartz | Level 8

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.

Ksharp
Super User

%macro ab(lib,ds);

%do i=1 %to 3;
%let x=%scan(&ds,&i,%str(,));

proc print data=&lib..&x;
run;
%end;

%mend;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 1111 views
  • 1 like
  • 5 in conversation