BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

data mdm;

 

do i=232 to 280;

output;

end;

format dt mmddyy10.;

run;

 

The above datastep creates a number sequence starting at 232 and ending at 280

The dataset I am working defines a date based on the number in month sequence.  For example

232 represents 01/31/15, 233 represents 02/28/15 etc.... i represents the numberic sequence.  How can I add a date sequence starting at 232 and a variable say dt and have it mirror the number sequence?  Also as you can see the number ends at 280, how can I set it up to continue for future months,  say 232 to the previous month even when the previous month becomes greater than 280???

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

 

data mdm;
new='31Jan2015'd;
do i=232 to 280 by 1;
j=i-232;
output;
new=intnx('month',new,1+j,'e');
end;
format new date9.;
run;
Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

 

data mdm;
new='31Jan2015'd;
do i=232 to 280 by 1;
j=i-232;
output;
new=intnx('month',new,1+j,'e');
end;
format new date9.;
run;
Thanks,
Jag
Astounding
PROC Star

Here's a variation on the theme:

 

data want;

do i=232 to 280;

   date = intnx('month', '31jan2015'd, i - 232, 'e');

   output;

end;

drop i;

run;

 

For your second question, you'll have to give an example of what "the previous month" means. I'm sure it's possible, but I'm not sure what needs to happen.

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
  • 2 replies
  • 3788 views
  • 1 like
  • 3 in conversation