05-23-2018 01:18 PM
This is my TXT file
Amanie Edmon Dabit
Jill Maret Daryan
Edward lawre Dunlap
Mark Jonathan Avery
Elea Christi Silver
Noel Kennin Arnold
Sonya Jane Taylor
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. ;
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 .
Does anyone know why this problem happen ?
05-23-2018 01:47 PM
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.
05-24-2018 02:08 AM
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.