DATA Step, Macro, Functions and more

Importing a .txt tab delimited file that also contains " "

Reply
Contributor
Posts: 22

Importing a .txt tab delimited file that also contains " "

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

Respected Advisor
Posts: 4,791

Re: Importing a .txt tab delimited file that also contains " "

@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;


 

 

Contributor
Posts: 62

Re: Importing a .txt tab delimited file that also contains " "

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;
Ask a Question
Discussion stats
  • 2 replies
  • 186 views
  • 2 likes
  • 3 in conversation