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)
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.
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.
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:
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.