Help using Base SAS procedures

infile error in sas9.4

Reply
Occasional Contributor
Posts: 13

infile error in sas9.4

This is my TXT file

 

342082109
Amanie Edmon Dabit
eco
267615672
Jill Maret Daryan
phy male 
229872244
Edward lawre Dunlap

female 
429155167
Mark Jonathan Avery
phy male
585628122
Elea Christi Silver
eco
285915791
Noel Kennin Arnold
edu female
490922411
Christopher Emerson
law male 
576639096
Sonya Jane Taylor
law male 

 

 

 

and this is my code ; 

 

data hw2.grade1_personal ;
infile 'filespecification.txt' firstobs=11 dlm='' missover ;
input #1 SSN 9.
#2 First $ 1-13 Middle $ 14-25 Last $ 26-35
#3 Major $ 7. Gender $ 8. ;

run;

 

 

I thought it was perfect for import data into sas data set ,

 

but last observation always failed to fill the variable "" Last ""  the blue one . 

 

asdasd.PNG

 

Does anyone know why this problem happen ?

 

 

 

Occasional Contributor
Posts: 13

Re: infile error in sas9.4

Posted in reply to LeeSeongWoo_

dlm , missover option ....

Super User
Posts: 13,508

Re: infile error in sas9.4

Posted in reply to LeeSeongWoo_

I think that you need to post your code and example data into a code box so that the windows on the forum do not reformat anything.

As currently shown the data and code would not produce the result shown.

When you specify columns to read from such as with

#2 First $ 1-13

with the shown data columns 1- 13 for the record you worry about are

 

Sonya Jane T

and that would be the value of the first name.

If your data is actually space delimited then do not specify columns to read from.

 

I suggest trying something that looks like:

data hw2.grade1_personal ;
   infile 'filespecification.txt' firstobs=11 dlm='' missover ;
   informat ssn 9. first $13. middle $11. last $10.
            major $7. gender $8.;
   input #1 SSN 
         #2 First Middle   Last 
         #3 Major  Gender 
   ;
run;

The informats will tell SAS the maximum expected length and the variable type (normally SSN should be character but that's another issue). then the Delimiter is actually used to separate the values. If you have multiple spaces between words then you may want to use the option DSD to treat multiple spaces as single delimiter.

 

 

 

Super User
Super User
Posts: 8,075

Re: infile error in sas9.4

The informats will tell SAS the maximum expected length and the variable type

Actually an INFORMAT is instructions to SAS on how to convert text to values.  It is only when the first reference to a variable in the data step occurs in the INFORMAT statement that it has any impact on the variable type or length. If you want to define the variable type and length it is better to use LENGTH or ATTRIB statements which are intended to be used to make those definitions.

 

Note that the informats you have used in that example actually do not give SAS any help in knowing how to convert the text in the input stream into the values to be stored. SAS already knows how to read character values and numbers.

 

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 164 views
  • 0 likes
  • 3 in conversation