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 | Y |
Thanks
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)?
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.