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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.