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.
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.
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.
@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.
Probably I should ask why the difference. anyways, I guess its hard explain here. Thank you guys for your response.
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 |
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?
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.
@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?
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.
@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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: