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.
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.
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
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.
Yes , it worked . But as i was using the other format is got the answer , but now its much better format.
Thanks
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.