BookmarkSubscribeRSS Feed
Miah
Obsidian | Level 7

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

2 REPLIES 2
Patrick
Opal | Level 21

@Miah

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;


 

 

JohnHoughton
Quartz | Level 8

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;

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 816 views
  • 2 likes
  • 3 in conversation