I am trying to automate the set statment using a loop and macros. Below is the code: libname abc "<path>"; %let startyr=2011; data _null_; today=today();ymm=month(today())-1; yyr=year(today()); if ymm=01 then do; yyr=year(today())-1; call symput('endyr', put(yyr, Z4.)); end; else call symput('endyr',put(year(today),z4.)); call symput('todaymm', put(ymm, Z2.)); run; %macro tloop; data temp1; set %do y=&startyr %to &endyr; %do i=1 %to 12; %if &i LT 10 %then %do; abc.myfile&y.0&i; %put abc.myfile&y.0&i; %end; %else %do; abc.myfile&y&i ;%put abc.myfile&y.&i; %end; %if &y=&endyr and &i=%eval(&todaymm-1) %then %do; stop; %end;; %end; if n=1 then stop; %end;; run; %mend tloop; %tloop; the desired output is data temp1; set abc.myfile201101 abc.myfile201102 abc.myfile201103 abc.myfile201104 abc.myfile201105 abc.myfile201106 abc.myfile201107 abc.myfile201108 abc.myfile201109 abc.myfile201110 abc.myfile201111 abc.myfile201112 abc.myfile201201 abc.myfile201202 abc.myfile201203 abc.myfile201204 abc.myfile201205 abc.myfile201206 abc.myfile201207 abc.myfile201208 abc.myfile201209 abc.myfile201210 abc.myfile201211 abc.myfile201212 abc.myfile201301 abc.myfile201302 abc.myfile201303 abc.myfile201304 abc.myfile201305 abc.myfile201306 abc.myfile201307 abc.myfile201308 abc.myfile201309 abc.myfile201310 abc.myfile201311 ; run; but when I run this code I get an error: abc.myfile201101 NOTE: Line generated by the macro variable "I". 31 abc.myfile201102 _____________________ 557 ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase. ERROR 557-185: Variable abc is not an object. am I making any mistake here? Or is there a better way to handle this? Thank you.
... View more