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,
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.
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,
Try adding statement
LIST;
after input to get an idea of what SAS is trying to read.
Add option truncover ?
data numbers; infile 'external-file' truncover ; input testnum 5.; run;
Post the log of the code and we will dissect it for you.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.