Overwrite check in and check out dates with first in and last out

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Overwrite check in and check out dates with first in and last out

Hi friends,

 

I'm running into a problem working with records that involve consecutive check in and check out dates. I have several lines per individual "stay." I want to select the first check in date and the last check out date and overwrite the rest of the dates for my analysis. I do not want to collapse/deduplicate the lines--I still want the same number of rows, but just the full date period. I have already written code to select the first check in, but can't figure out how to overwrite with the last check out.

 

Example:

LastNameFirstNameCheck_inCheck_out
BieberJustin14-Feb-1322-Feb-13
BieberJustin14-Feb-1316-Mar-13
BieberJustin14-Feb-1321-Mar-13
SpearsBritney29-Mar-135-Apr-13
OceanFrank17-May-1328-May-13
WestKanye24-Aug-1325-Aug-13
WestKanye24-Aug-1326-Aug-13
WestKanye24-Aug-1329-Aug-13
WestKanye24-Aug-1330-Aug-13

 

This is what I want it to look like:

LastNameFirstNameCheck_inCheck_out
BieberJustin14-Feb-1321-Mar-13
BieberJustin14-Feb-1321-Mar-13
BieberJustin14-Feb-1321-Mar-13
SpearsBritney29-Mar-135-Apr-13
OceanFrank17-May-1328-May-13
WestKanye24-Aug-1330-Aug-13
WestKanye24-Aug-1330-Aug-13
WestKanye24-Aug-1330-Aug-13
WestKanye24-Aug-1330-Aug-13

 

Can anybody help me out??

 

Hopefully! Robot Embarassed


Accepted Solutions
Solution
‎08-24-2016 04:58 PM
Grand Advisor
Posts: 17,333

Re: Overwrite check in and check out dates with first in and last out

Whatever your 'grouping' variables are, add them to the GROUP statement.

 

 

View solution in original post


All Replies
Grand Advisor
Posts: 17,333

Re: Overwrite check in and check out dates with first in and last out

That's a bit of a weird request but ok...

SQL works well here. Use the Select * to select all level records and then use the max/min to get the earliest/latest dates in your dataset.

 

proc sql;
create table want as
select *, min(check_in) as check_in_start, max(check_out) as check_out_end
from have
group by lastName, FirstName
order by lastName, FirstName, check_in;
quit;
Occasional Contributor
Posts: 5

Re: Overwrite check in and check out dates with first in and last out

Oh! This is really close to what I am looking for, however there is one problem (my apologies, I should have considered this before!).

 

If the same person has a new stay (involving new check in date), I would want to retain those visits as separate. Example:

 

LastNameFirstNameCheck_inCheck_out
BieberJustin14-Feb-1322-Feb-13
BieberJustin14-Feb-1316-Mar-13
BieberJustin14-Feb-1321-Mar-13
DionCeline29-Mar-135-Apr-13
HoustonWhitney17-May-1328-May-13
BieberJustin24-Aug-1325-Aug-13
BieberJustin24-Aug-1326-Aug-13
BieberJustin24-Aug-1329-Aug-13
BieberJustin24-Aug-1330-Aug-13

 

To this:

LastNameFirstNameCheck_inCheck_out
BieberJustin14-Feb-1321-Mar-13
BieberJustin14-Feb-1321-Mar-13
BieberJustin14-Feb-1321-Mar-13
DionCeline29-Mar-135-Apr-13
HoustonWhitney17-May-1328-May-13
BieberJustin24-Aug-1330-Aug-13
BieberJustin24-Aug-1330-Aug-13
BieberJustin24-Aug-1330-Aug-13
BieberJustin24-Aug-1330-Aug-13

 

I should note that I also have unique id numbers for these individuals.

 

P.S. Thank you for your high tolerance for the obsurity of my request!

Solution
‎08-24-2016 04:58 PM
Grand Advisor
Posts: 17,333

Re: Overwrite check in and check out dates with first in and last out

Whatever your 'grouping' variables are, add them to the GROUP statement.

 

 

Occasional Contributor
Posts: 5

Re: Overwrite check in and check out dates with first in and last out

There we go! Thank you!
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 272 views
  • 2 likes
  • 2 in conversation