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)?
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.