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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 630 views
  • 1 like
  • 2 in conversation