BookmarkSubscribeRSS Feed
azee007
Calcite | Level 5

I have to make checkin and check out columns from IM ID IY and OM OD OY columns , and then find the days of stay by subtracting checkout - checkin , but could not get the results.

 

 

data hotel;
INFILE 'hotel.dat';
INPUT Room Guests IM ID IY OM OD OY ;
run;

 

data format;
length checkin $20 checkout $20;
set hotel;
checkin=mdy(IM,ID,IY);
checkout=mdy(OM,OD,OY);
format checkin checkout mdy;
run;

data format;
length days;
days=checkout-checkin;
run;

proc print data=format;
run;

 

I am not able to formate checkin and checkout as dates , so that i can get a new variable daydiff from checkin and checkout days.

Hope to hear soon.

 

6 REPLIES 6
Reeza
Super User

You should be getting errors? Your format statement is incorrect. I suggest using a date9 format instead. 

Make sure you have a clean log. 

 

You second data step is missing a SET statement so it has no input dataset to process. You don't need two steps though, just use one. 

azee007
Calcite | Level 5

I have tried date9 , but it is not running and giving errors . I have also tried mmddyy10. , that also doesn't work, i have used date10. , that also doesn't work . Please tell me in code where i have to use date9 ..

 

Also,i need to know that if i have guests who are 1 or more than 1 in numbers like 2,3 , 5 ,8. I need to multiply with room rate and guests more than 1 ( where 1 guest is free) and above 1 guest its $10 per guest. I am not able to make code.Plz help

 

 

Reeza
Super User

I don't understand your remaining questions. You'll have to rephrase them and provide examples 

the following should work based on the assumption your data is being read in correctly. 

 

data format;

set hotel;

checkin=mdy(IM,ID,IY);
checkout=mdy(OM,OD,OY);

format checkin checkout date9. ;

days=checkout-checkin;

run;

proc print data=format;
run;

If this doesn't work,, post the exact code you submit AND the log with the errors. 

azee007
Calcite | Level 5

Yes , it worked . But as i was using the other format is got the answer , but now its much better format. 

 

Thanks 

 

Reeza
Super User

Make sure your days are correct with hotel definition. 

 

You're doing stragiht subtraction there, which is number of nights booked. The number of days is often +1 in travel speak, or 6 night/7-day trip. 

 

PGStats
Opal | Level 21

Also, the statement

 

length checkin $20 checkout $20;

 

declares the two variables as character strings. But SAS dates returned by function MDY are numbers. Remove the length statement and SAS will understand that checkin and checkout are numbers.

PG

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