BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Niugg2010
Obsidian | Level 7

Below is my macro:

%macro try(dsns=);

%let dsnnum=%sysfunc(countw("&dsns.", ' ,;:'));

%put &dsnnum.;

%do k=1 %to &dsnnum.

%let dsn=%scan(&dsns., &k., %str( ,));

%put &dsn.;

%end;

%mend ;

%try(dsns=%str(aaa, bbb, ccc))

 

For the first loop, I want it &dsn=aaa, second loop &dsn=bbb, third loop &dsn=ccc;

 

when I run above code, it produces some errors:

 

WARNING: Apparent symbolic reference K not resolved.

WARNING: Apparent symbolic reference K not resolved.

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric

operand is required. The condition was: &k.

ERROR: Argument 2 to macro function %SCAN is not a number.

 

 

Someone can help me out?

 

Thanks

George

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Niugg2010,

 

Adding the missing semicolon after

%do k=1 %to &dsnnum.

would help a lot.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Your first %LET statement has what appear to be unbalanced quotes.  Why are you using quotes anyway?

Why are you making your task harder by adding commas in the value you are passing to macro?

If it is a list of dataset names then just use spaces between the names.

%macro try(dsns);
  %local dsnnum k dsn;
  %let dsnnum=%sysfunc(countw(&dsns,%str( )));
  %put &=dsnnum ;
  %do k=1 %to &dsnnum ;
    %let dsn=%scan(&dsns., &k., %str( ));
    %put &=k &=dsn;
  %end;
%mend try ;

%try(dsns=aaa bbb ccc)
FreelanceReinh
Jade | Level 19

Hi @Niugg2010,

 

Adding the missing semicolon after

%do k=1 %to &dsnnum.

would help a lot.

Niugg2010
Obsidian | Level 7
Got it. Thanks

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
  • 3 replies
  • 704 views
  • 0 likes
  • 3 in conversation