BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
amandav2107
Calcite | Level 5

I'm looking to limit my data set by an actual admit and release date.  Here is my dataset:

 

ObsFACILITYIDadmitadmittimeclientreltimereleasedaysinadmitcount
485B613-Jun-2313:012713875613:0728-Jun-2346
486A55-Jun-2313:012713875613:078-Jun-2345
487A430-May-2312:122713875613:005-Jun-2374
488B329-May-2319:522713875612:1030-May-2323
489A29-May-2310:062713875619:5229-May-23212
490B111-Apr-230:532713875610:049-May-23291

 

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:

ObsFACILITYIDadmitadmittimeclientreltimereleasedaysinadmitcount
485B613-Jun-2313:012713875613:0728-Jun-2346
490B111-Apr-230:532713875613:078-Jun-23631

 

 

Can anyone help?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
amandav2107
Calcite | Level 5

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

ballardw
Super User

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.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

Register now

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
  • 3 replies
  • 627 views
  • 0 likes
  • 3 in conversation