I am having trouble importing this data set into SAS. It is a tab delimited file, that also contains " in the title names and date data. How can I fix it? Here it is my code, and right after it is the error message that I am getting:
proc import datafile="/folders/myfolders/KCHomes.txt"
REPLACE;
DELIMITER='09'x;
GETNAMES=YES;
run;
DATA KCHomes;
RUN;
ERROR:
The table "WORK.KCHOMES" cannot be opened because it does not contain any columns
A very quick and easy way to import such data is to use the EG (or SAS Studio) import wizard. This will generate the code for you and the only thing you have to change in this generated code is the file path and the delimiter.
Here how such generated code looks like:
DATA WORK.KCHomes;
LENGTH
date 8
price 8
bedrooms 8
bathrooms 8
sqft_living 8
waterfront $ 3
condition 8
grade 8
yr_built 8 ;
FORMAT
date MMDDYY10.
price BEST7.
bedrooms BEST1.
bathrooms BEST4.
sqft_living BEST4.
waterfront $CHAR3.
condition BEST1.
grade BEST2.
yr_built BEST4. ;
INFORMAT
date MMDDYY10.
price BEST7.
bedrooms BEST1.
bathrooms BEST4.
sqft_living BEST4.
waterfront $CHAR3.
condition BEST1.
grade BEST2.
yr_built BEST4. ;
INFILE 'C:\temp\KCHomes.txt'
firstobs=2
LRECL=43
ENCODING="WLATIN1"
TERMSTR=CRLF
DLM='09'x
MISSOVER
DSD ;
INPUT
date : ?? MMDDYY10.
price : ?? BEST7.
bedrooms : ?? BEST1.
bathrooms : ?? COMMA4.
sqft_living : ?? BEST4.
waterfront : $CHAR3.
condition : ?? BEST1.
grade : ?? BEST2.
yr_built : ?? BEST4. ;
RUN;
Your code works for me if I just add the out= option and get rid of the bit that says " data kchomes ; run;"
proc import datafile="KCHomes.txt" out=kchomes
REPLACE;
DELIMITER='09'x;
GETNAMES=YES;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.