Hi, There is a data set in a library which is produced monthly in general, say e.g. SOURCE.SALES_YYYYMM Here is SOURCE is a library nam, SALES_YYYYMM is data set name and YYYYMM is 201201 for the month of Jan2012. But some months, the data set is not produced. However, whenever i run a particular piece of code that needs to use the latest of those series of data set. e.g. .................. data result; set SOURCE.SALES_201204(keep=var1 var2 var3); run; .................. At the moment before running the code i manually check and replace the data set with the latest one in the code. I want to avoid that manual intervention and automate that process, and wrote the following code. %macro choose_latest; %let YYYYMM =%sysfunc(putn( %sysfunc(today()),yymmn6.)); %let data_set = SOURCE.SALES_&YYYYMM; %if %sysfunc(exist(&data_set.)) %then; %else %do; i =1; %do %while( i ne 0); call symput( 'YYYYMM' , %sysfunc(putn( %sysfunc(intnx(month,%sysfunc(today()),-i,b)),yymmn6.))); call symput('data_set', "SOURCE.SALES_&YYYYMM"); %if %sysfunc(exist(&data_set.)) %then i=0; %else i=i+1; %end; %end; %mend; %choose_latest; However, when i submit the code the session just freezes and doesn't respond. Would any one help me to fix the problem?. Many thanks in advance.
... View more