I have folders as F_001 , F_002, F_003, F_004, F_005, F_011
and each folder has Data_1 , Data_2, Data_3, Data_4, Data_5, Data_10
if i give prompt x as 1,3,4 it should count the number of arguments in the macro x now macro x has 3 arguments so it should loop
three times .
PROMPT FORMAT X= 1,3,4
%macro test(type);
%let type = c;
/* first find whether the delimiter is comma seperated
%if index(&x,',') > 0 %then %do;
%let n = %sysfunc(countw(&x,',');
%do k=1 %to &n ; / * will loop three times one for x=1 and then x=3 and then x=4 */
%let start = %substr(&x,&k,1);
%let end = %substr(&x,&k,1);
%do pt = &start %to &end; / * In this case start will be 1 and end will be 1 as its looping for first time */
%let folder_name = F_00&pt;
%if &pt ge 10 %then %do;
%let folder_name = F_0&pt; /* (here folder_name resolves to F001) */
%end;
%test2(&folder_name,&type);
%end;
%end;
Please Suggest me correct syntax as above code is not working but concept is same
This seems really close to these questions:
https://communities.sas.com/t5/Base-SAS-Programming/SAS-Scan/m-p/405858/highlight/false#M98754
I would also suggest looking at the Macro Appendix which now has a list of examples that may help you out.
To what end, what is it you want out at the end. The reason being is that Base SAS is a really powerful language for data manipulation and can do this type of work far better than macro which only generates Base SAS code. You you take this prompt and want to run a macro on all datasets within the given libraries. You could go your way, or you could just say:
data _null_; do i=1 to countw("&x.",","); call execute(cats('%domacro (l=f_',put(input(scan("&x.",i,","),best.),z3.),');')); end; run;
This will loop over each comma delimited value in &x, and for each one call the macro domacro, with the parameter f_ and the value from the list. Far simpler. Macro is not a replacement for Base SAS!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.