Truncover and Missover

Reply
Occasional Contributor
Posts: 6

Truncover and Missover

Hi,

Why truncover and missover when used with datalines statement and when used with an external file behave differently.

Eg;

data a;

infile datalines truncover;

input chr $3.;

datalines;

a

bb

ccc

dddd

eeeee

ffffff

;

run;

data b;

infile datalines missover;

input chr $3.;

datalines;

a

bb

ccc

dddd

eeeee

ffffff

;

run;

Both these if executed gives the same results.

But when instead of using the datalines statement if i use an external file and execute the same program i get different results.

a,txt in the below examples contain

a

bb

ccc

dddd

eeeee

ffffff

.

data a;

infile 'a.txt' truncover;

input chr $3.;

run;

data b;

infile 'a.txt' missover;

input chr $3.;

run;

N/A
Posts: 1

Re: Truncover and Missover

truncover---keep;

missover---drop.

Occasional Contributor
Posts: 6

Re: Truncover and Missover

But i am concerned about the output which appear differently when i execute the programs as is mentioned above. Can you help me on this

Respected Advisor
Posts: 3,900

Re: Truncover and Missover

The difference between TRUNCOVER and MISSOVER is that if SAS encounters an "end-of-line" indicator earlier than the length of the variable mapped against the input record then TRUNCOVER will return the partial string but MISSOVER will return a missing.

So in your case with the external file the first 2 records map a variable with a format of $3. against an input string which has a "end-of-line" indicator at position 2 or 3. So MISSOVER will return a missing.

I personally can't be bothered and that's why I'm always using TRUNCOVER.

You can circumvent such and effect by either using Informats instead of formats when reading data - or by defining a logical record length and padding the records (see code below).

data b;

  infile 'a.txt' missover lrecl=3 pad;

  input chr $3.;

run;

or

data b;

  infile 'a.txt' missover;

  input chr :$3.;

run;

Now with DATALINES (CARDS) SAS reads the data in-stream. I remember that Tom once explained very explicitly the differences between reading from an external file and using in-stream reading - but unfortunately I can't find the thread anymore nor recall fully Tom's explanation.

But basically: You don't hit the "end-of-line" indicator there and that's why MISSOVER and TRUNCOVER behave the same.

Super User
Super User
Posts: 6,502

Re: Truncover and Missover

Basically CARDS (datalines) have an implied PAD. 

Ask a Question
Discussion stats
  • 4 replies
  • 858 views
  • 2 likes
  • 4 in conversation