BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
philip_
Fluorite | Level 6

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:
sas.jpg
 
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
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

At a guess your changing the variable your working on, try:

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

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

At a guess your changing the variable your working on, try:

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 806 views
  • 1 like
  • 2 in conversation