Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

database - What does SAS do if you try to read past the end of a record?

With this code, I write lines of 109 characters.

DATA _NULL_;
    SET  TP_FREQ_DATA;
    FILE TPFREQ01;
    OUT = MESSAGE_TYPE || ORIG_ADDR_ID || ORIG_SUB_ADDR_ID || EDI_VERSION || PUT(ERROR_DATA,$3.);
    PUT OUT $CHAR109.;
RUN;

Next I read it back in, specifying positions further than the 109the character

DATA TEST;                   
     INFILE TPFREQ01 LRECL=109 ; 
     INPUT 
         @1    RECTYPE   $CHAR3.    /* RECORD TYPE  */ 
         @04   ROAD      $CHAR8.    /* SENDING ROAD */ 
         @116  VERSION   $CHAR12.   /* EDI VERSION  */ 
         @1947 ERRORS    $CHAR3.    /* ERROR 1      */ 
         ;     
     IF RECTYPE ^= '421' THEN DELETE;                
     IF ERRORS ^= ' ' THEN ERRORS = 'YES';           
       ELSE ERRORS = 'NO';          
RUN;

Can anyone help with the value of VERSION and ERRORS because the lengths of one line is 109 but the pointers is at 116 and 1947.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With the default FLOWOVER infile option when you attempt to move past the end of the line with the pointer control you will instead move to the start of the next line. So @116 VERSION $CHAR12. will read the first 12 characters of the second line and @1947 ERRORS $CHAR3. will read the first three characters of the third line.

You can see this in action by using the COLUMN= option on the INFILE statement.

data test;
 infile cards column=cc ;
 put 'START ' cc= ;
 input @1 v1 $char3. @ ;
 put v1= cc= _infile_;
 input @200  v2 $char3. @;
 put v2= cc= _infile_;
 input @100 v3 $char3. @;
 put v3= cc= _infile_;
cards;
1234567890
ABCDEFGHIJ
KLMNOPQRST
;

Results:

START cc=1
v1=123 cc=4 1234567890
v2=ABC cc=4 ABCDEFGHIJ
v3=KLM cc=4 KLMNOPQRST
START cc=4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...