BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sam1231
Obsidian | Level 7
option mlogic merror symbolgen;
 
* Generate Macro List for all the paths in each tab;
  %let pathlist= &prodpro;
  %put &pathlist;

 %let i=1;
%DO %WHILE (%SCAN(&pathlist,&i,")") ne %STR( ));
	%LET path=%SCAN(&pathlist,&i,")");
	%put &path;

	
%put "Reading &dsn.";
     %genexcel(dir=&path);
	%LET i=%EVAL(&i. + 1);
%END;

above code is giving me below error

ERROR: Macro function %SCAN has too few arguments.
SYMBOLGEN: Macro variable I resolves to 1
ERROR: Required operator not found in expression: %SCAN(&pathlist,&i,")") ne
ERROR: The condition in the %DO %WHILE loop, %SCAN(&pathlist,&i,")") ne  , yielded an invalid
or missing value, . The macro will stop executing.

 

My pathlist value is

 

\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\Pgmm)

 

Please can some help me?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The %SUPERQ() function takes the name of a single macro variable.

You could combine the values first.

%let pathlist=&prodpro.&prodpro1.&prodpro2.&prodpro3;
%let pathlist=%superq(pathlist);

If that is your real goal then change your scan logic to use some other character as the delimiter. For example you could use | since that is invalid to include in a real path.  That will also mean that most likely you will not need to apply any macro quoting to your paths.  But if you allow silly things like "Joe's Files" as part of the path then the unbalanced single quote will still need to macro quoting.

data pathlist;
  infile cards truncover ;
  input path $200.;
cards;
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\Pgmm
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\ot
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\lst
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\gfh
;

proc sql noprint;
 select path into :pathlist separated by '|'
  from pathlist 
 ;
quit;
%let pathlist=%superq(pathlist);
.....
%do i=1 %to %sysfunc(countw(&pathlist,|));
  %let path=%scan(&pathlist,|);

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

The value of your macro variable is confusing the macro processor.

289   %let string=xxx);
290   %let word1=%scan(&string,1);
ERROR: Macro function %SCAN has too few arguments.

Look at what code you asked SAS to interpret.

291   %put scan(&string,1);
scan(xxx),1)

Add some macro quoting. Since you seem to be making a new macro variable why not just add the macro quoting when making that variable.  Also eliminate the quotes from the list of delimiters you are asking %SCAN() to use otherwise you will get unexpected results when the path list includes quotes.

%let prodpro=\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\Pgmm);
%let pathlist= %superq(prodpro);
%do i=1 %to %sysfunc(countw(&pathlist,%str(%))));
  %let path=%scan(&pathlist,&i,%str(%)));
sam1231
Obsidian | Level 7

Thank you tom! its working

 

But i am trying to apply below  4 %let macro variable  to one macro variable

 

%let pathlist=%superq(prodpro prodpro1 prodpro2 prodpro3);

 

%let prodpro=\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\Pgmm)
%let prodpro1=\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\ot)
%let prodpro2=\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\lst)
%let prodpro3=\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\gfh)

 

i want to run my macro loop for 4 time(for each and every path). do you have any suggestions?

Tom
Super User Tom
Super User

The %SUPERQ() function takes the name of a single macro variable.

You could combine the values first.

%let pathlist=&prodpro.&prodpro1.&prodpro2.&prodpro3;
%let pathlist=%superq(pathlist);

If that is your real goal then change your scan logic to use some other character as the delimiter. For example you could use | since that is invalid to include in a real path.  That will also mean that most likely you will not need to apply any macro quoting to your paths.  But if you allow silly things like "Joe's Files" as part of the path then the unbalanced single quote will still need to macro quoting.

data pathlist;
  infile cards truncover ;
  input path $200.;
cards;
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\Pgmm
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\ot
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\lst
\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\gfh
;

proc sql noprint;
 select path into :pathlist separated by '|'
  from pathlist 
 ;
quit;
%let pathlist=%superq(pathlist);
.....
%do i=1 %to %sysfunc(countw(&pathlist,|));
  %let path=%scan(&pathlist,|);
sam1231
Obsidian | Level 7
%macro team;
%macro av(ot=);
data ag;
    path="&ot";
	output;
run;
%mend;

option mlogic merror symbolgen;
 
%let pathlist=%superq(pathlist);

%put &pathlist;
* Generate Macro List for all the paths in each tab;
%let pathlist=%superq(pathlist);
%do i=1 %to %sysfunc(countw(&pathlist,|));
  %let path=%scan(&pathlist,&i,|);
	%put &path;
     %av(ot=&path);
         
	%LET i=%EVAL(&i. + 1);
%END;

%mend team;

%team;

i updated code as per your suggestion and its working.

 

but its not executing for for 2nd value.

 

my pathlistvalue=

\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\Pgmm|\\\gmt\rtg-yup99\ststic\myfolder\folder\study\2007\adam\Pdng\ot

 

its execute first value only. 

 

its not taking 2nd value after |

 

 

Tom
Super User Tom
Super User

The way you have coded your loop you are counting by twos.  1,3,5,7.

remove the extra increment to the loop counter.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1708 views
  • 2 likes
  • 2 in conversation