DATA Step, Macro, Functions and more

how to get check in and check out days and then difference of these date

Reply
Contributor
Posts: 34

how to get check in and check out days and then difference of these date

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.

 

Super User
Posts: 17,912

Re: how to get check in and check out days and then difference of these date

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. 

Contributor
Posts: 34

Re: how to get check in and check out days and then difference of these date

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

 

 

Super User
Posts: 17,912

Re: how to get check in and check out days and then difference of these date

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. 

Contributor
Posts: 34

Re: how to get check in and check out days and then difference of these date

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

 

Thanks 

 

Super User
Posts: 17,912

Re: how to get check in and check out days and then difference of these date

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. 

 

Respected Advisor
Posts: 4,659

Re: how to get check in and check out days and then difference of these date

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
Ask a Question
Discussion stats
  • 6 replies
  • 243 views
  • 0 likes
  • 3 in conversation