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)
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: