BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
he_ko
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

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;
he_ko
Fluorite | Level 6

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!

Reeza
Super User

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

 

 

he_ko
Fluorite | Level 6
There we go! Thank you!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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