BookmarkSubscribeRSS Feed
Arashi02
Calcite | Level 5

Hi, I have a file named "list2.txt"

And would like to read it into SAS.

However, I don't understand why the gender for Mary Wong and the Profit for John Leung cannot be read successfully.

 

May anyone pls explain it to me?

Many thanks!!!

 

My code:

data case5b;

infile '~/MS3251_2022/Raw Data/list2.txt' missover;

input age 1-3 name $ 5-19 profit 20-29 sex $ 31-33;

run;

 

(list2.txt and output)

Arashi02_0-1665074656073.png

 

3 REPLIES 3
ballardw
Super User

Suggestion:

Copy those lines from the text file. On the forum open a text box using the </> icon and paste the example text.

The main message windows will reformat text and I am afraid that pictures do not describe data files very well as there are characters that affect how data is read that may not appear in a picture.

 

Also, were there any messages in the Log about invalid data or reading issues like "Lost Card"?

 

You can't read the Sex for Mary Wong because when the columns 31-33 are read column 32 is the end of line character.

With John Leung  is that when attempting to read columns 20-29 is that at column 26 the Input statement encounters the end of line (that arrow) OR some other character that cannot be treated as part of a number.

 

When you read an explicit column there must be a value there. It may be that your file is actually a delimited file using a TAB character. TABS often make people think values appear in specific columns because many values align sort of nicely. But can't tell, as I said with a picture though that indent before John Wong when the 19 is shifted one character the right different than the line above it in the first picture is indicative of Tab characters.

Tom
Super User Tom
Super User

Take look at what is in the text file.

data _null_;
  infile '~/MS3251_2022/Raw Data/list2.txt' ;
  input;
  list;
run;

 

Also do NOT use the ancient MISSOVER option.  That will throw away values that are too short. Use the modern (only 30+ years old) TRUNCOVER option instead.  That will use the last value on the line even if it is shorter that what you are trying to input.

Kurt_Bremser
Super User

Open the text file with a text editor (Notepad should do it, unless it's really big), then copy/paste the text (say, 10 lines, including the header) into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 289 views
  • 0 likes
  • 4 in conversation