Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Count how many days pass between two periods

is there a way to count how many days pass from a start-end to the next one? Let say:

   ID            Start            End    
 0001          22JAN2022       23JAN2022 
 0001          26JAN2022       30JAN2022          
 0001          03MAR2022       08MAR2022    
 0001          09MAR2022       15MAR2022    
 0001          17MAR2022       30MAR2022     

desired output:

   ID            Start            End           days 
 0001          22JAN2022       23JAN2022         3
 0001          26JAN2022       30JAN2022         4   
 0001          03FEB2022       08MAR2022         1
 0001          09MAR2022       15MAR2022         2
 0001          17MAR2022       30MAR2022      .......   

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I believe I demonstrated this in another thread but there you go

data have;
input ID $ (Start End)(:date9.);
format Start End date9.;
datalines;
0001 22JAN2022 23JAN2022 
0001 26JAN2022 30JAN2022 
0001 03FEB2022 08MAR2022 
0001 09MAR2022 15MAR2022 
0001 17MAR2022 30MAR2022 
;

data want;
   set have;
   by ID;
   set have(firstobs = 2 rename = start = s keep = start)
       have(obs = 1 drop = _all_);
   if last.ID then s = .;
   days = s - end;
run;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading