BookmarkSubscribeRSS Feed
sridhar78
Calcite | Level 5

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:-

Male27180.
Female293145.
Female342103.
Male3521124.
Female364163.
Male21150.
Male25292.
Female211426
5 REPLIES 5
Patrick
Opal | Level 21

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;

sridhar78
Calcite | Level 5

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.

Patrick
Opal | Level 21

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?

sridhar78
Calcite | Level 5

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.

data_null__
Jade | Level 19

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 926 views
  • 0 likes
  • 3 in conversation