BookmarkSubscribeRSS Feed
LeeSeongWoo_
Fluorite | Level 6

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 ?

 

 

 

3 REPLIES 3
LeeSeongWoo_
Fluorite | Level 6

dlm , missover option ....

ballardw
Super User

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.

 

 

 

Tom
Super User Tom
Super User

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.

 

 

 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 765 views
  • 0 likes
  • 3 in conversation