Read in variable block file with blank line delimiter

Reply
Occasional Contributor
Posts: 6

Read in variable block file with blank line delimiter

 

I am working with a file that has two variables with variable lengths (address variables that I’ve turned into arrays). I can read these variables in fine, but following the second variable the format changes a bit. The first 358,747 lines contain a variable that does not exist in lines after the 358,747th line. The 358,747th line is blank and should serve as a delimiter.

 

I can’t seem to figure out how to make this work though. The code is a little complicated because of the variables with a variable length, but I’ll paste what I have below. I currently am using _N_ in a conditional statement to read in the different formats appropriately. However, in the future, the blank delimiter may not be the 358,747th line so I need to figure out how to condition on the blank line delimiter.

 

I thought about using a macro variable (with call symput?), but I was having trouble making that work.

 

I’ve highlighted the relevant parts (perhaps ignore most of the rest), but if you want to try to reason through it, then each array variable has a length of 22, and the number of populated arrays depends on the address counter (ADDRESS_CTR or  IRA_ADDRCTR) preceding the variable. I'm not reading in all variables either, so honestly I wouldn't bother trying to figure everything out. I may not be doing this the most efficient way, but it does work. Also, I recognize there’s some conversion between numeric and character values that hasn’t been done explicitly. I’m not worried about this right now. Feel free to provide suggestions though if you think I’m being ridiculous.

 

I'm working with SAS/STAT 13.2 on a mainframe Z/os platform.

 

FILENAME SAMPLEFILE ("SAMPLEFILELOCATION") DISP=SHR;
DATA SAMPLE;
ARRAY ADDRLINE $22. ADDRLINE1-ADDRLINE6;
ARRAY IRA_ADDRLINE $22 IRA_ADDRLINE1-IRA_ADDRLINE6;
INFILE SAMPLEFILE MISSOVER;
INPUT
@1 ABC $1.
@2 DEF $9.
@48 ACTIONDATE $2.
@55 GHI $8.
@68 ADDRESS_CTR $PHEX2. @;

 

/*Identify blank line here*/


ADDRESS_CTR2 = INPUT(SUBSTR(ADDRESS_CTR,1,2),2.);

IF ADDRESS_CTR2 >0;

DO AA = 1 TO ADDRESS_CTR2;
POS1 = 69 + 22*(AA-1);
IF ADDRESS_CTR2 = AA THEN POS2 = 69+22*AA;

INPUT @POS1 ADDRLINE{AA} $22. @;
END;

POSCANCELDATE = POS2 + 131;
POS3 = 197+POS2;

INPUT @POSCANCELDATE CANCELDATE $6.
@POS3 ADDR_IRACTR $PHEX2. @;

ADDR_IRACTR2 = INPUT(SUBSTR(ADDR_IRACTR,1,2),2.);

DO AA = 0 TO ADDR_IRACTR2;
IF AA = 0 THEN DO;
IF ADDR_IRACTR2 = 0 THEN POS6 = POS3+1;
END;
ELSE DO;
POS5 = POS3 +1 + 22*(AA-1);
IF ADDR_IRACTR2 = AA THEN POS6 = POS3+1+22*AA;
INPUT @POS5 IRA_ADDRLINE{AA} $22. @;
END;
END;

IF _N_ < 358748 THEN DO;

POSCONDITIONALVARIABLE = POS6 + 5;
POSJKLINDIC = POS6 + 9;
POSACTIONINDIC = POS6 + 11;

INPUT @POSCONDITIONALVARIABLE CONDITIONALVARIABLE $4.
@POSJKLINDIC JKLINDIC $2.
@POSACTIONINDIC ACTIONINDIC $2.;
END;
ELSE DO;
POSJKLINDIC = POS6 + 5;
POSACTIONINDIC = POS6 + 7;
INPUT @POS6 ZIPIRA $5.
@POSJKLINDIC JKLINDIC $2.
@POSACTIONINDIC ACTIONINDIC $2.;
END;

IF CHECKAMT >0;
ACTIONDATE = CATS(ACTIONINDIC, ACTIONYY);
IF ACTIONDATE >0;

RUN;

Super User
Posts: 13,532

Re: Read in variable block file with blank line delimiter

Perhaps you might test with the option FLOWOVER instead of MISSOVER.

 

Consider this brief example:

data junk;
   infile datalines flowover;
   input a $ b $ c $;
datalines;
a b c
1 2 3
p d

q
4 5

6
;
run;

To see if the data is a reasonable substitute for yours and the result makes sense.

 

Of course if you may lots of other missing data then this won't work but if MISSOVER was included as a default coding item it is worth testing.

Ask a Question
Discussion stats
  • 1 reply
  • 68 views
  • 0 likes
  • 2 in conversation