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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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