Get the dataset names from dictionary.tables and filter according to your requirements:
data data_2015Q4; x=1; run;
data data_2015Q3; x=2; run;
data data_2015Q2; x=3; run;
data data_2015Q1; x=4; run;
data data_2014Q4; x=5; run;
data data_2014Q3; x=6; run;
data data_2014Q2; x=7; run;
data data_2014Q1; x=8; run;
data data_2013Q4; x=9; run;
data data_2013Q3; x=10; run;
data data_2013Q2; x=11; run;
data data_2013Q1; x=12; run;
%let rptDate=31Dec2015;
proc sql noprint;
create table rptList as
select memname
from dictionary.tables
where libname="WORK" and
memname like "DATA_____Q_" and
intnx("QTR",input(scan(memname,2,"_"), ? yyq6.),0,"END") between
intnx("QTR", "&rptDate"d, -8, "END") and
"&rptDate"d;
select memname
into:setList separated by " "
from rptList order by memname desc;
select catx("_", "inp", min(scan(memname,2,"_")), max(scan(memname,2,"_")))
into:setName trimmed
from rptList;
drop table rptList, &setName;
quit;
data &setName;
set &setList;
run;
proc print; run;
I would change your process so that it appends the dataset to the 'master' dataset at the end of the process.
Alternatives are to store all the output with a consistent naming structure in a library.
If you use a prefix that isn't used with any other datsets you can refer to it with a colon to append all datasets with the same prefix.
Ie this would append all datasets starting with IMP.
data want;
set imp: ;
run;
data have; input date date9.; cards; 31Dec2015 31mar2016 ; run; data temp; set have; length list $ 400; do i=-1 to -9 by -1; list=catx(' ',list,'data_'||put(intnx('qtr',date,i),yyq.)); end; data=catx('_','inp',put(intnx('qtr',date,-9),yyq.),put(date,yyq.)); drop i; run; data _null_; set temp; call execute(catx(' ','data',data,';set',list,';run;')); run;
Still the same thing : %let date=31dec2015; data temp; length list $ 400; do i=-1 to -9 by -1; list=catx(' ',list,'data_'||put(intnx('qtr',"&date"d,i),yyq.)); end; data=catx('_','inp',put(intnx('qtr',"&date"d,-9),yyq.),put("&date"d,yyq.)); drop i; run; data _null_; set temp; call execute(catx(' ','data',data,';set',list,';run;')); run;
Still the same thing : %let date=31dec2015; data temp; length list $ 400; do i=-1 to -9 by -1; list=catx(' ',list,'data_'||put(intnx('qtr',"&date"d,i),yyq.)); end; data=catx('_','inp',put(intnx('qtr',"&date"d,-9),yyq.),put("&date"d,yyq.)); drop i; run; data _null_; set temp; call execute(catx(' ','data',data,';set',list,';run;')); run;
Get the dataset names from dictionary.tables and filter according to your requirements:
data data_2015Q4; x=1; run;
data data_2015Q3; x=2; run;
data data_2015Q2; x=3; run;
data data_2015Q1; x=4; run;
data data_2014Q4; x=5; run;
data data_2014Q3; x=6; run;
data data_2014Q2; x=7; run;
data data_2014Q1; x=8; run;
data data_2013Q4; x=9; run;
data data_2013Q3; x=10; run;
data data_2013Q2; x=11; run;
data data_2013Q1; x=12; run;
%let rptDate=31Dec2015;
proc sql noprint;
create table rptList as
select memname
from dictionary.tables
where libname="WORK" and
memname like "DATA_____Q_" and
intnx("QTR",input(scan(memname,2,"_"), ? yyq6.),0,"END") between
intnx("QTR", "&rptDate"d, -8, "END") and
"&rptDate"d;
select memname
into:setList separated by " "
from rptList order by memname desc;
select catx("_", "inp", min(scan(memname,2,"_")), max(scan(memname,2,"_")))
into:setName trimmed
from rptList;
drop table rptList, &setName;
quit;
data &setName;
set &setList;
run;
proc print; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.