BookmarkSubscribeRSS Feed
SRINIVAS_N
Calcite | Level 5

%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

7 REPLIES 7
Reeza
Super User
Can you explain the overall issue? There are ways to shortcut reference data set lists, such as colon or - operator. But it depends on your requirements.

ie SET dsn_201301-dsn_201305; is perfectly valid.
SRINIVAS_N
Calcite | Level 5
In the set statement datasets should be dynamic
Kurt_Bremser
Super User

@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.

ballardw
Super User

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.

SRINIVAS_N
Calcite | Level 5
I should not write statically it should be dynamic
Astounding
PROC Star

Is this close enough to being dynamic?

 

set dsn_20: ;

 

It takes all data set names that begin with "dsn_20"

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1156 views
  • 0 likes
  • 5 in conversation