sas macross

Reply
Contributor
Posts: 62

sas macross

 

 

 

%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

Super Contributor
Posts: 490

Re: sas macross

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

Contributor
Posts: 62

Re: sas macross

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

 

 

Contributor
Posts: 62

Re: sas macross

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

Super User
Posts: 5,366

Re: sas macross

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.

Super Contributor
Posts: 490

Re: sas macross

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

Contributor
Posts: 62

Re: sas macross

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

Contributor
Posts: 62

Re: sas macross

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

 

Contributor
Posts: 55

Re: sas macross

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.

Super User
Posts: 9,867

Re: sas macross

%macro ab(lib,ds);

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

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

%mend;

Ask a Question
Discussion stats
  • 9 replies
  • 632 views
  • 1 like
  • 5 in conversation