BookmarkSubscribeRSS Feed
prattipati
Calcite | Level 5

Hi ,

 

I got below data and need to Calulate the number days each the status stayed. I need to populate the last two fileds ?

 

I need flag when the status changes and number of days in each status . Please let me know if you need any further infomration . thanks 

 

Code ID Date Status Status Change Flag No of days in each status
55 ABC 25-Jan-12 Y    
29 ABC 22-Mar-12 Y    
56 ABC 05-Jan-13 N    
60 ABC 03-Feb-14 N    
91 ABC 15-May-15 N    
81 ABC 09-Oct-16 Y    
98 ABC 09-Dec-16 Y    
102 ABC 25-Jan-18 Y    
105 ADR 05-Jan-13 N    
125 ADR 09-Oct-16 N    
135 ADR 25-Jan-18 N    
155 ADR 05-May-19 Y    
168 ADR 15-Jun-20    

Thanks

1 REPLY 1
Kurt_Bremser
Super User

For the status change, use the LAG function. For the number of days, keep the first date in a RETAINed variable.

How do you want to calculate the duration (what should be used as the end date)?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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