DATA Step, Macro, Functions and more

Diffrence between infile method and list input method when using missover and truncover?

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Diffrence between infile method and list input method when using missover and truncover?


Accepted Solutions
Solution
3 weeks ago
Super User
Super User
Posts: 8,069

Re: Diffrence between infile method and list input method when using missover and truncover?

Posted in reply to ramchinna24

The INPUT statement will only work the same if it is reading the same thing.

 

If the file has 80 characters on each line (that is it is padded with spaces) then SAS will treat it same as the 80 characters that sees when reading in-line data.

 

For example consider what will happen with the MISSOVER option when you try to read 5 characters from a line that only has 3 characters on it.  The value will be set to missing.  That is the whole point of the MISSOVER option.  But when you are reading from in-line data the input buffer is padded to the next multiple of 80 bytes. So the line has 80 characters on it and the input sees the three digts and two spaces and knows how to read that.

View solution in original post


All Replies
PROC Star
Posts: 2,329

Re: Diffrence between infile method and list input method when using missover and truncover?

Posted in reply to ramchinna24

So many places where this is already covered, like here.

If you want an explanation, do your research, read the documentation and then ask questions if anything is unclear.

 

Contributor
Posts: 35

Re: Diffrence between infile method and list input method when using missover and truncover?

I am not after the diffrence between missover and truncover. I am looking for the  difference in the results when we read data from external file(eg text file with data control methods) and when we create data using control methods(missover truncover etc).  still if you do not understand my question I will explain in more details.

Thank you for your response.

Super User
Super User
Posts: 8,069

Re: Diffrence between infile method and list input method when using missover and truncover?

Posted in reply to ramchinna24

@ramchinna24 wrote:

I am not after the diffrence between missover and truncover. I am looking for the  difference in the results when we read data from external file(eg text file with data control methods) and when we create data using control methods(missover truncover etc).  still if you do not understand my question I will explain in more details.

Thank you for your response.


Still not getting the question. If you want to test the differences for a specific data file then run the code and check the results.

Contributor
Posts: 35

Re: Diffrence between infile method and list input method when using missover and truncover?

Probably I should ask why the difference. anyways, I guess its hard explain here. Thank you guys for your response.

PROC Star
Posts: 2,329

Re: Diffrence between infile method and list input method when using missover and truncover?

Posted in reply to ramchinna24

1. If I understand correctly, this is a odd question: Options work the same way whether you read a file or cards.

 

2. As suggested, just test yourself when you have this kind of questions.

data _null_;
  file "%sysfunc(pathname(WORK))\t.txt"  ;
  put 'A B     ';
  put 'A       ';
  put 'A B     ';
run; 
    
data FILE_EMPTY;
  infile "%sysfunc(pathname(WORK))\t.txt" ;
  input VAR1 $ VAR2 $;
run; 
           
data FILE_MISSOVER;
  infile "%sysfunc(pathname(WORK))\t.txt" missover;
  input VAR1 $ VAR2 $;
run; 

data FILE_STOPOVER;
  infile "%sysfunc(pathname(WORK))\t.txt" stopover;
  input VAR1 $ VAR2 $;
run; 

data CARDS_EMPTY;
  infile cards ;
  input VAR1 $ VAR2 $;
cards;
A B
A
A B
run; 
                
data CARDS_MISSOVER;
  infile cards missover;
  input VAR1 $ VAR2 $;
cards;
A B
A
A B
run; 
                 
data CARDS_STOPOVER;
  infile cards stopover;
  input VAR1 $ VAR2 $;
cards;
A B
A 
A B
run; 
                        
proc print data=FILE_EMPTY     noobs; title 'FILE_EMPTY    '; run;
proc print data=CARDS_EMPTY    noobs; title 'CARDS_EMPTY   '; run;
proc print data=FILE_MISSOVER  noobs; title 'FILE_MISSOVER '; run;
proc print data=CARDS_MISSOVER noobs; title 'CARDS_MISSOVER'; run;
proc print data=FILE_STOPOVER  noobs; title 'FILE_STOPOVER '; run;
proc print data=CARDS_STOPOVER noobs; title 'CARDS_STOPOVER'; run;

 

FILE_EMPTY

VAR1 VAR2
A B
A A

 


CARDS_EMPTY

VAR1 VAR2
A B
A A

 


FILE_MISSOVER

VAR1 VAR2
A B
A  
A B

 


CARDS_MISSOVER

VAR1 VAR2
A B
A  
A B

 


FILE_STOPOVER

VAR1 VAR2
A B

 


CARDS_STOPOVER

VAR1 VAR2
A B
Contributor
Posts: 35

Re: Diffrence between infile method and list input method when using missover and truncover?

[ Edited ]

Thank you  I understood this. My question is 

code1:

DATA TEST;
INFILE datalines (*)OVER;
INPUT TESTNUM 5.;
datalines;
55555
1
22
333
4444
55555
;
RUN;

 

code2:

DATA TEST;
INFILE "/r00/home/ram.txt" (*)OVER;
INPUT TESTNUM 5.;
RUN;

 

These code1 and code2 should give same results right. what is the reason that they are not providing same results when we use control methods for eg: missover?

 

Solution
3 weeks ago
Super User
Super User
Posts: 8,069

Re: Diffrence between infile method and list input method when using missover and truncover?

Posted in reply to ramchinna24

The INPUT statement will only work the same if it is reading the same thing.

 

If the file has 80 characters on each line (that is it is padded with spaces) then SAS will treat it same as the 80 characters that sees when reading in-line data.

 

For example consider what will happen with the MISSOVER option when you try to read 5 characters from a line that only has 3 characters on it.  The value will be set to missing.  That is the whole point of the MISSOVER option.  But when you are reading from in-line data the input buffer is padded to the next multiple of 80 bytes. So the line has 80 characters on it and the input sees the three digts and two spaces and knows how to read that.

Super User
Posts: 13,498

Re: Diffrence between infile method and list input method when using missover and truncover?

Posted in reply to ramchinna24

@ramchinna24 wrote:

I am not after the diffrence between missover and truncover. I am looking for the  difference in the results when we read data from external file(eg text file with data control methods) and when we create data using control methods(missover truncover etc).  still if you do not understand my question I will explain in more details.

Thank you for your response.


Without an explicit file, specific options, the input statement and informats used the "difference" can be very hard to explain.

 

When reading your file do you check the log to see if you get any "invalid data" messages? Or "SAS went to next line" or such?

 

Super User
Super User
Posts: 8,069

Re: Diffrence between infile method and list input method when using missover and truncover?

[ Edited ]
Posted in reply to ramchinna24

When you are reading from in-line data (DATALINES a.k.a. CARDS) they are padded to a multiple of 80 bytes. Like real keypunch cards.

 

Try making two different external files. One with trimmed lines and one with 80 column lines.

data _null_;
  length line $80 ;
  do line=
'55555'
,'1'
,'22'
,'333'
,'4444'
,'55555'
  ;
  len=length(line);
  file 'short.txt' ;
  put line $varying80. len ;
  file 'fixed.txt' ;
  put line $80. ;
run;

You should see that  the one with fixed length lines behaves the same as the in-line data.

Super User
Posts: 13,498

Re: Diffrence between infile method and list input method when using missover and truncover?


@Tom wrote:

When you are reading from in-line data (DATALINES a.k.a. CARDS) they are padded to a multiple of 80 bytes. Like real keypunch cards.

 

 


This option is controllable with the system option CARDIMAGE or NOCARDIMAGE. If the option is set to NOCARDIMAGE then lines can be longer than 80-byte records. NOCARDIMAGE seems to be the default installation option, at least in SAS 9.4

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 158 views
  • 4 likes
  • 4 in conversation