Date: Thu, 12 Feb 2004 16:20:36 -0500
Reply-To: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject: Re: Parsing Variable Length File
Content-Type: text/plain; charset=ISO-8859-1
Try this:
data _null_;
input @'LN' howlong 2. lastname $varying. howlong
@'MN' howlong 2. materalname $varying. howlong ;
put lastname= materalname=;
cards;
XXXXXXXXXXXXXXXUSYYYYYYYYYY12LN04FAIRMN07SHANNON......
;
Result:
lastname=FAIR materalname=SHANNON
On Thu, 12 Feb 2004 13:05:32 -0500, Shannon Fair <s.fair@CRIFGROUP.COM>
wrote:
>I am trying to read a variable length flat file with both fixed and
>variable length segments. Reading each variable length segment requires
>searching for and finding each field’s tag and length in order to identify
>the value in those fields. For example, to begin reading the first
>segment, I have to find a 2-byte tag (LN) of the first field (Last Name) in
>that segment. Immediately following this tag is the 2-byte length of the
>Last Name field. Since this field contains a name of eight bytes, the
>record would read LN08 followed by an 8-byte character: LN08FRANKLIN. Here
>is a short example of the first part of one record:
>
>XXXXXXXXXXXXXXXUSYYYYYYYYYY12LN04FAIRMN07SHANNON......
>
>data test (DROP=LENGTHPN LENGTHMN);
> infile 'e:\above file.txt' missover;
> input User_ref $15.
> Cntry_cd $2.
> Memb_cd $10.
> Prim_cd 1.
> Sec_cd 1.
> /*Name Segment*/
> PN $2.
> lengthPN 2. @;
> call symput ('format',lengthPN); /* I know this
>doesn't work, but I would like it to*/
> input Paternal_Name $&format..
> MN $2.
> lengthMN 2. @;
> call symput ('format',lengthMN); /* I know this
>doesn't work, but I would like it to*/
> input Maternal_Name $&format..
>;
>run;
>
>I cannot figure out a way to resolve the macro 'format' variable & I have
>tons of segments to parse plus a large amount of records - therefore, I
>only want to make one pass through the data.
>
>Any suggestions???
>
>Thanks!
|