BookmarkSubscribeRSS Feed
Kurt_Bremser
Super User

@Yona22 wrote:
Hi, I used the code but just listed out all the dataset. May I know how can I put all of them together in a new data?

Did you run my call execute code? It will automatically pick up all datasets in the range that follow the naming pattern.

Yona22
Calcite | Level 5
 
Patrick
Opal | Level 21

@Yona22 

Below fully working and tested code using your table names.

/* create sample source tables */
%macro doit();
  data _null_;
    length source_dslist $2000;
    do year=0 to 20;
      do month=1 to 12;
        source_dslist=catx(' ',source_dslist, cats('tab', put(year,z2.),put(month,z2.)));
       end;
    end;
    call symputx('source_dslist', source_dslist);
    stop;
  run;
%mend;
%doit();
data &source_dslist tab0203_copy tab0215;
  set sashelp.class(obs=2);
run;

/* create list of source tables within desired date range.
   and store result in macro variable &dslist
*/
%let dslist=;
proc sql noprint;
  select cats(libname,'.',memname) into :dslist separated by ' '
  from dictionary.tables
  where libname='WORK' and substr(memname,1,3)='TAB'
    and input(compress(memname,,'kd'),yymmn4.) between '01mar2002'd and '01dec2019'd
  order by memname
  ;
quit;
%put &=dslist;

/* combine all source tables */
data want;
  length _inds $41;
  format payment_date yymmn4.;
  set &dslist indsname=_inds;
  payment_date=input(compress(_inds,,'kd'),yymmn4.);
run;

proc print data=want(obs=2);
run;