I'm looking to limit my data set by an actual admit and release date. Here is my dataset:
Obs | FACILITY | ID | admit | admittime | client | reltime | release | daysin | admitcount |
485 | B | 6 | 13-Jun-23 | 13:01 | 27138756 | 13:07 | 28-Jun-23 | 4 | 6 |
486 | A | 5 | 5-Jun-23 | 13:01 | 27138756 | 13:07 | 8-Jun-23 | 4 | 5 |
487 | A | 4 | 30-May-23 | 12:12 | 27138756 | 13:00 | 5-Jun-23 | 7 | 4 |
488 | B | 3 | 29-May-23 | 19:52 | 27138756 | 12:10 | 30-May-23 | 2 | 3 |
489 | A | 2 | 9-May-23 | 10:06 | 27138756 | 19:52 | 29-May-23 | 21 | 2 |
490 | B | 1 | 11-Apr-23 | 0:53 | 27138756 | 10:04 | 9-May-23 | 29 | 1 |
I want to have an output of two rows that show an "admit" date of 11-Apr-23 and a "releaze" date of 8-Jun-23 & an "admit" date of 13-Jun-23 and a "releaze" date of 28-Jun-23. I also want to either LAG the daysin (days between date count) or do a recount once the LAG is successfully complete.
Like this:
Obs | FACILITY | ID | admit | admittime | client | reltime | release | daysin | admitcount |
485 | B | 6 | 13-Jun-23 | 13:01 | 27138756 | 13:07 | 28-Jun-23 | 4 | 6 |
490 | B | 1 | 11-Apr-23 | 0:53 | 27138756 | 13:07 | 8-Jun-23 | 63 | 1 |
Can anyone help?
I have no clue what your are requesting with LAG or that stated recount.
IF your date variables are SAS date values you specify litteral dates using the 'ddMONyy'd values.
So maybe something like:
data want; set have; where ( admit = '11APR2023'd and release = '08JUN2023'd) or ( admit = '13JUN2023'd and release = '28JUN2023'd) ; run;
Please pick one name for the variable. Showing the variable in "example" data a "release" and then asking questions about "releaze" makes one question as to which it really is or if there is another variable.
Best is to provide example data in the form of working data step code so we don't have to ask about whether variables are numeric or character and what the real names may be.
Also, show the expected values of any requested calculations an be prepared to discuss details about steps to get there.
Could you please explain how the original data of 6 rows is converted into an output showing just two rows? Please explain in words, step-by-step, leaving nothing out.
Could you also please explain the meaning of the word LAG in this situation?
I manipulated the table in Excel. The table with the two rows shows my desired output. I've tried to LAG every subsequent "admit" and "releaze" date, which got all 10 dates on one record, but I wasn't able to further limit the record to only keep two sets of dates like in the table I posted with the two rows (desired output).
I have no clue what your are requesting with LAG or that stated recount.
IF your date variables are SAS date values you specify litteral dates using the 'ddMONyy'd values.
So maybe something like:
data want; set have; where ( admit = '11APR2023'd and release = '08JUN2023'd) or ( admit = '13JUN2023'd and release = '28JUN2023'd) ; run;
Please pick one name for the variable. Showing the variable in "example" data a "release" and then asking questions about "releaze" makes one question as to which it really is or if there is another variable.
Best is to provide example data in the form of working data step code so we don't have to ask about whether variables are numeric or character and what the real names may be.
Also, show the expected values of any requested calculations an be prepared to discuss details about steps to get there.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.