## re: Increment dates

Solved
Regular Contributor
Posts: 247

# re: Increment dates

Hi....I would like to create a table consisting of a list a dates that increment by year from the startday and stops at the endday. Is it simpler to use %dateloop or find the number of years between the two dates %do -to approach.

DATA ABC;

startday = 20040401;

endday = input(strip(put(intnx('Year.4',today(),-2,'B'),yymmddn8.)),8.);

dif = intck('year',startday,endday);

run;

%do i=0 to &dif;

/*advances the date i years from the start date */

%let date=%sysfunc(putn(%sysfunc(intnx(year,&startday,&i,b)),8.));

%put &date=;

%end;

Accepted Solutions
Solution
‎01-27-2014 10:23 PM
Esteemed Advisor
Posts: 5,521

## Re: re: Increment dates

If by table you mean a dataset then you could do this:

%let startDay=01APR2004;

data dates;

endDay = intnx("YEAR.4", today(), -2);

date = "&startDay."d;

do while(date <= endDay);

output;

date = intnx("YEAR", date, 1, "SAME");

end;

drop endDay;

format date yymmdd10.;

run;

proc print data=dates noobs; run;

PG

PG

All Replies
Solution
‎01-27-2014 10:23 PM
Esteemed Advisor
Posts: 5,521

## Re: re: Increment dates

If by table you mean a dataset then you could do this:

%let startDay=01APR2004;

data dates;

endDay = intnx("YEAR.4", today(), -2);

date = "&startDay."d;

do while(date <= endDay);

output;

date = intnx("YEAR", date, 1, "SAME");

end;

drop endDay;

format date yymmdd10.;

run;

proc print data=dates noobs; run;

PG

PG
Regular Contributor
Posts: 247

## Re: re: Increment dates

Hi PG.....that is exactly what I wanted...works perfectly....thanks for all your help.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 2 replies
• 231 views
• 0 likes
• 2 in conversation