BookmarkSubscribeRSS Feed
Sas_Act_114
Fluorite | Level 6

Hello,

 

I have a table with two date variables that make a date range (as an example, Var1 is 01/01/2019 and Var2 is 06/30/2019). I want to take that rows and split it into multiple rows, with a row for each month within the date range. Thus in the example I have, the one record would be split into six records (201901, 201902, 201903, etc..). I know this is somehow possible with the INTCK and INTNX function and using some kind of loop, but I can not figure out how to use them properly to get the results I want. Any help would be appreciated, thank you!

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Use the Intnx Function like this

 

data have;
input (Var1 Var2)(:mmddyy10.);
format Var: mmddyy10.;
datalines;
01/01/2019 06/30/2019
;

data want(drop = i);
   set have;
   do i = 0 by 1 while (1);
      dt = intnx('month', Var1, i, 'b');
      if dt > Var2 then leave;
      output;
   end;

   format dt yymmn6.;
run;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 874 views
  • 0 likes
  • 2 in conversation