Here is my code. I do not have any errors, but I am having problems with zip code, address and vehicle (last 3 variables in input statement). How do I correctly fix my code so that these 3 variables show up correctly? Please help. Thank you in advanced.
data November2;
length Firstname $7 Lastname $8; */used length statement to have names display first;
infile '/courses/ddb976e5ba27fe300/PSY6560/ExternalData/HotelOccupancyNov18_v2.dat';
input Checkindate:ANYDTDTE20. Checkoutdate:ANYDTDTE20.
roomrate:comma. FirstName:$7. LastName:$6.
zipcode:comma3. address &:$40. vehicle $;
format checkindate date10. checkoutdate date10. roomrate dollar12.2;
run;
datalines;
5-Nov-18 7-Nov-18 $105.00 Jordan Bailey 101 Wrong Way Alexandria TN 37012 N
3-Nov-18 4-Nov-18 $150.00 Sydney Ashton 210 Freeway Auburntown TN 37016 Y
3-Nov-18 6-Nov-18 $95.00 Taylor Darby 555 New Way Elkton TN 38455 N
31-Oct-18 . $105.00 Payton Finley 888 Final Way Englewood TN 37329 Y
2-Nov-18 5-Nov-18 $105.00 Spencer Greer 757 Airport Way Cold Spring KY 41076 Y
4-Nov-18 5-Nov-18 $100.00 Adrian Hayden 000 No Way Columbus KY 42032 Y
7-Nov-18 . $160.00 Casey Harper 666 Devil's Way Crestview Hills KY 41017 Y
;
run;
What were you told about the content of '/courses/ddb976e5ba27fe300/PSY6560/ExternalData/HotelOccupancyNov18_v2.dat' ?
Is it a delimited file where commas, tabs or some other character separates values or is it fixed column? or something else.
If the file is supposed to be delimited then likely you only need is to provide the delimiter option on the infile statement such as
dlm=',' (comma separated) or dlm='09'x (tab delimited since tab characters don't show will in code the hex equivalent is used).
One thing is if your zip code is 5 characters then using COMMA3 to read the data would at a minimum truncate the value to 3 characters.
I am afraid that datalines as pasted no longer represents your example data if it ever did. The message window on this forum reformats text and so your datalines may not have all of the characters you had originally. Additionally typed datalines probably do not actually represent your file well. If you do not have a description of your DAT file you should paste a few lines from it directly into a code box opened using the forum's {I} icon. That box preserves text as pasted.
Hello @smart,
If you want to read the data from the data lines, remove both the INFILE statement and the first RUN statement and proceed as described below:
length vehicle $1;
if length(scan(address,-1,' '))=1 then do;
vehicle=scan(address,-1,' ');
address=substr(address,1,length(address)-1);
end;
This assumes that VEHICLE has only values of length 1 and that ADDRESS is never missing.Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.