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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 17 replies
  • 2988 views
  • 3 likes
  • 6 in conversation