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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.