BookmarkSubscribeRSS Feed
mich_ard
Fluorite | Level 6

Hi everyone,

 

I got a question about reading raw data:

 

----+----1----+----2
1
22
333
4444
55555

  I used following codes with a fixed width of 5.

data numbers;
   infile 'external-file'; 
   input testnum 5.;
run;

the output result is:

22
4444
55555


I don't understand this output.

 

First line has only 1 digit, plus 2nd line (2 digits), still not enough, right? I guess it goes to 3 line, ok! but why it picks up only 22, instead of pick them up together? (eg. 12233). For the remaining 2 lines it's the same way to read, it should get 44445. So my expectation is:

 

12234

44445

 

am I correct? or where is the problem?

 

Thanks.

 

Mike,

5 REPLIES 5
ballardw
Super User

If you check the log you will likely see some warnings about  reading past the end of line.

 

When you include the format on the input statement as you have done you will FORCE the reading of 5 characters.

 

To get your likely desired result of 5 records:

data numbers;
   infile 'external-file'; 
   informat testnum 5.;
   input testnum ;
run;

Which says read the next value as an integer of up to 5 characters. If less then no error if longer only 5 are read.

 

mich_ard
Fluorite | Level 6

thanks for your reply. What you said is very helpful for me to understand how to use informat. My question still remains: why the output result is:

22
4444
55555

 mike,

PGStats
Opal | Level 21

Try adding statement 

 

LIST;

 

after input to get an idea of what SAS is trying to read.

PG
Ksharp
Super User

Add option truncover ?

 

data numbers;
   infile 'external-file' truncover ; 
   input testnum 5.;
run;

 

ballardw
Super User

Post the log of the code and we will dissect it for you.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1618 views
  • 0 likes
  • 4 in conversation