Hi,
I have a text file (test4.txt) which has the following columns
Gender, Age, S1, S2, S3 and S4. Here S1-S4 are numeric variables.
The program or code below worked fine on SAS desktop learning edition. But when I ran it on the EG 4.3 it is not reading correctly.
The data on the last columns it not being read. Sometimes zero is read as zero and sometimes it is read as"blank/null"
How do I ensure that SAS reads the data correctly? Please advice.
The code I wrote is below:-
data lib2.test4;
infile "/home/sridhar78/sridharv/test4.txt";
input gender$ age s1 s2 s3 s4;
run;
Data file "text4.txt"
Male 27 1 8 0 0
Female 29 3 14 5 10
Female 34 2 10 3 3
Male 35 2 112 4 8
Female 36 4 16 3 7
Male 21 1 5 0 0
Male 25 2 9 2 1
Female 21 1 4 2 6
The output I get is as below:-
Male | 27 | 1 | 8 | 0 | . |
Female | 29 | 3 | 14 | 5 | . |
Female | 34 | 2 | 10 | 3 | . |
Male | 35 | 2 | 112 | 4 | . |
Female | 36 | 4 | 16 | 3 | . |
Male | 21 | 1 | 5 | 0 | . |
Male | 25 | 2 | 9 | 2 | . |
Female | 21 | 1 | 4 | 2 | 6 |
Can you please attach your test file "test4.txt" so that we can have a look into it. I assume it has something to do with delimiters and/or end-of-line indicators.
Are you running your code under Windows or Unix?
You could try:
infile "/home/sridhar78/sridharv/test4.txt" TRUNCOVER;
Hi Patrick,
I'm unable to attach the txt file. Hence I've pasted the data above.
Test4 is a regular text file and the delimiter is space.
There are no inconsistencies such as missing data, wrong delimiter, etc.
To answer your question, I'm running the code in Windows.
I tried using TRUNCOVER, but still seeing the same output. Please advice.
thanks for your prompt response.
The forums here allow you to attach a file. What's holding you back?
The reason I'm after the original data source is that I suspect the issue is somewhere with whitespace characters (so a TAB instead of a BLANK or LF instead of CRLF as end-of-line indicators). This is something which can only be detected by looking into the original data source.
I kind-of suspect end-of-line indicators as interestingly the very last line of your data gets read as you want it. Does this file - by any chance - originate from a Unix environment?
I've attached the file by editing my question. I couldn't attach the file in my reply (that was the issue preventing me from attaching it).
Please check.
I'm not sure about the origin of the data file (whether Unix env. or not). I'm assuming it was created in windows.
You need to include the infile statement option TERMSTR=CRLF;
When you switched the program from desktop SAS to EG you changed the OS to UNIX, I suspect.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: