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!
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: