BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ramchinna24
Obsidian | Level 7
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

10 REPLIES 10
ChrisNZ
Tourmaline | Level 20

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.

 

ramchinna24
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

@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.

ramchinna24
Obsidian | Level 7

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

ChrisNZ
Tourmaline | Level 20

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
ramchinna24
Obsidian | Level 7

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?

 

Tom
Super User Tom
Super User

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.

ballardw
Super User

@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?

 

Tom
Super User Tom
Super User

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.

ballardw
Super User

@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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1820 views
  • 5 likes
  • 4 in conversation