DATA Step, Macro, Functions and more

A simple question about reading raw data in SAS

Reply
Occasional Contributor
Posts: 11

A simple question about reading raw data in SAS

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,

Super User
Posts: 10,521

Re: A simple question about reading raw data in SAS

[ Edited ]

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.

 

Occasional Contributor
Posts: 11

Re: A simple question about reading raw data in SAS

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,

Respected Advisor
Posts: 4,654

Re: A simple question about reading raw data in SAS

Try adding statement 

 

LIST;

 

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

PG
Super User
Posts: 9,687

Re: A simple question about reading raw data in SAS

Add option truncover ?

 

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

 

Super User
Posts: 10,521

Re: A simple question about reading raw data in SAS

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

Ask a Question
Discussion stats
  • 5 replies
  • 255 views
  • 0 likes
  • 4 in conversation