%let start_year=2013;
data time_period(drop=year month);
do year=&start_year to year(today());
do month=1 to 12;
tp=input(compress(year||put(month, z2.)), 6.);
if tp>put(today(), yymmn6.) then
delete;
output;
end;
end;
run;
proc sql;
select count(tp)
into : cnt
from time_period;
quit;
proc sql;
select tp
into :pk1 - :pk%sysfunc(compress(&cnt))
from time_period
order by tp;
quit;
%macro datasets;
%do date=1 %to &cnt;
data dsn_&&pk&date;
x=10;
run;
%end;
%mend Datasets;
%datasets
the datasets will create as
dsn_201301
dsn_201302
dsn_201303
dsn_201304
dsn_201305
.
.
.till today (dsn_201810)
what ever datasets are creating all datasets has to append a one dataset dynamically.
like
data one;
set dsn_201301 dsn_201302 dsn_201303 ...............dsn_201810
@SRINIVAS_N wrote:
In the set statement datasets should be dynamic
That's exactly what the macro is for. It creates SAS dates in monthly sequence. Just use the proper format and build the dataset names with the resulting strings.
I'm not sure if the question is creating a bunch of data sets or combining them.
If the sets already exist then no need to create a set statement listing every single one unless you have some that you need to exclude for some reason.
data one;
set dsn_201301 - dsn_201810;
run;
should work.
So if you need need specific start and end "dates" you only need that, start and end.
Is this close enough to being dynamic?
set dsn_20: ;
It takes all data set names that begin with "dsn_20"
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.