user2568648
user2568648

Reputation: 3201

Import text file into SAS

I'm importing a text file into SAS, using the code below :

proc import datafile="C:\Users\Desktop\data.txt" out=Indivs dbms=dlm replace;
 delimiter=';';
   getnames=yes;
run;

However, I get error messages in the log and certain fields are populated with "." in place of the real data and I don't know what is the problem.

The error message is :

Invalid data for DIPL in line 26 75-76.
Invalid data for DIPL in line 28 75-76.
Invalid data for DIPL in line 31 75-76.
Invalid data for DIPL in line 34 75-76.

A sample of the data is available here http://m.uploadedit.com/b029/1392916373370.txt

Upvotes: 2

Views: 37279

Answers (3)

Siva Kandrekula
Siva Kandrekula

Reputation: 1

If log has this "Number of names found is less than number of variables found." then it creates new variables which have blank values.

Upvotes: 0

Joe
Joe

Reputation: 63434

Don't use PROC IMPORT in most cases for delimited files; you should use data step input. You can use PROC IMPORT to generate initial code (to your log), but most of the time you will want to make at least some changes. This sounds like one of those times.

data want;
infile "blah.dat" dlm=';' dsd lrecl=32767 missover;
informat
trans $1.
triris $1.
typc $6.
;
input
trans $
triris $
typc $
... rest of variables ...
;
run;

PROC IMPORT generates code just like this in your log, so you can use that as a starting point, and then correct things that are wrong (numeric instead of character, add variables if it has too few as the above apparently does, etc.).

Upvotes: 5

Allan Bowe
Allan Bowe

Reputation: 12701

I copied the text file from your link, and ran your code (without the apostrophe):

proc import datafile="C:\temp\test.txt" out=Indivs dbms=dlm replace;
 delimiter=';';
   getnames=yes;
run;

And it worked fine despite the following:

Number of names found is less than number of variables found.

Result:

NOTE: WORK.INDIVS data set was successfully created.
NOTE: The data set WORK.INDIVS has 50 observations and 89 variables.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.30 seconds
      cpu time            0.26 seconds

enter image description here

Upvotes: 1

Related Questions