## Get each last day of preceding months

Solved
Occasional Contributor
Posts: 7

# Get each last day of preceding months

Hello,

I wanted to create a dataset called timestamps that lists the last day of each month of the preceding 6 months. My solution for this is:

``````DATA timestamps;
d = today();
format d date9.;
DO i=0 TO 5;
d = intnx('month',d,-i)-1;
output;
END;
run;``````

However, I get this as result:

If I "rerun the loop manually", I get the day I expect. E.g. this code
``````DATA timestamps;
d = today();
format d date9.;
d = intnx('month',d,-1)-1;
run;``````
gives: 31MAY2017

Why do I get 30APR2017 for i =1 in the loop? What is wrong in my loop?
Thanks for the help!

Kind regards,
philip

Accepted Solutions
Solution
‎07-06-2017 04:43 AM
Super User
Posts: 9,599

## Re: Get each last day of preceding months

```data timestamps;
d = today();
format d dt date9.;
do i=0 to 5;
dt=intnx('month',d,-i)-1;
output;
end;
run;```

All Replies
Solution
‎07-06-2017 04:43 AM
Super User
Posts: 9,599

## Re: Get each last day of preceding months

```data timestamps;
d = today();
format d dt date9.;
do i=0 to 5;
dt=intnx('month',d,-i)-1;
output;
end;
run;```
☑ This topic is solved.