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
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)
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.