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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1417 views
  • 0 likes
  • 2 in conversation