data have; infile datalines dsd truncover; input id num (start end) (:date9.); format start end date9.; datalines4; 101,2,12MAR2018,18MAR2018 101,3,15MAR2018,19MAR2018 101,4,20MAR2018,29MAR2018 102,2,12JAN2018,19JAN2018 102,3,20JAN2018,28JAN2018 102,4,29JAN2018,12FEB2018 102,5,13FEB2018,18FEB2018 102,6,19FEB2018,28FEB2018 ;;;; run; data want; infile datalines dsd truncover; input id num (start end) (:date9.); format start end date9.; datalines4; 101,2,12MAR2018,13MAR2018 101,2,14MAR2018,15MAR2018 101,2,16MAR2018,18MAR2018 101,3,15MAR2018,19MAR2018 101,4,20MAR2018,29MAR2018 102,2,12JAN2018,19JAN2018 102,3,20JAN2018,28JAN2018 102,4,29JAN2018,12FEB2018 102,5,13FEB2018,18FEB2018 102,6,19FEB2018,28FEB2018 ;;;; run;
I need to split first nums with 2 days duration for 2 times as shown in want. any suggestion? if the total duration is less than 4 then it should split in num3 for all id's.
Why is 101,2 the only record split?
data have;
infile datalines dsd truncover;
input id num (start end) (:date9.);
format start end date9.;
datalines4;
101,2,12MAR2018,13MAR2018
101,3,16MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
run;
data need;
set have;
by id num;
retain end1;
format end1 date9.;
If first.id then do;
do i=1 to 3;
if i=1 then do; start=start; end1=start+1; output; end;
if i=2 then do; start=end1+1; end1=start+1; output; end;
if i=3 then do; start=end1+1; end1=end;output; end;
If end1=end then i =4;
end;
end;
Else do;
End1=end; output; end;
run;
i used the below code but it somehow doesnt split if the first num doesnt have enough duration
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.