LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 13 Oct 2001 19:32:00 +0000
Reply-To:     Puddin' Man <pudding_man@POSTMARK.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Puddin' Man <pudding_man@POSTMARK.NET>
Subject:      Re: reading hierarchical file w. varying number of sub-records
Comments: To: Jim Moody <moody.77@OSU.EDU>
Content-Type: multipart/mixed;

Hi,

Your message might be easier to respond to if you'd turn off (beloved, beloved) html ...

I find the design of your flat-file to be rather poor. Someone prepares the file for you? If at all possible, I'd request the file be redesigned so that the number of type 2, 3 etc records be written to the single type=1 record for each case. For a single case, this might look something like:

126 2 1 216 236 321

Reading such data should be relatively straightforward.

For the data you described, the following (tested W2kP SAS 8.1) code might suggest an approach:

*** code to read data when rectype is in (1,3): ***; data a(drop=_:); infile 'dum1.dat' end=e1; *** for x,y data when rectype in (2,3): ***; array x(2,5) r2x1-r2x5 r3x1-r3x5; array y(2,5) r2y1-r2y5 r3y1-r3y5;

*** read the first record for a case: ***; input rectype 1 r1x1 2 r1y1 3; if rectype ne 1 then put 'Ooooooooops:' _all_;

*** check to see if there are no more recs for this case: ***; input _next 1 @@; if _next = 1 then return;

*** read groups of recs when rectype > 1: ***; _i=0; cycle: _i+1; do _j=1 by 1 until (not(rectype=_next)); input rectype 1 x(_i,_j) 2 y(_i,_j) 3; if not(e1) then input _next 1 @@; else _next=.; end;

*** go back, get the data for the next highest rectype: ***; if _next > 1 then goto cycle; run;

The code is structured to accomodate record types of 1,2, and 3; As you can see, your chosen var names are hardcoded in the array statements. The code uses 'input ... @@;' to look ahead, see what the next record type is, take the appropriate action. In case anyone has forgotten, the '@@' holds the input line for the next iteration of the data step. The code assumes a max of 5 recs/case for any given record type.

The code also contains one instance of "The Demon GOTO". Seems I average about one GOTO per year. If you belong to the religion of "Thou Shalt Not GOTO" perhaps you can fiddle the initialization of _next and nest the 'do until' or somesuch. I considered doing this and rejected the idea: it looks perfectly 'natural' to po' me as is.

Hope it hep's ...

Puddin'

******************************************************* *** Puddin' Man *** Pudding_Man@postmark.net ***** *******************************************************;

"Look out, kid, they keep it all hid!" -from "Subterranean Homesick Blues", "Country Bob" (from Hibbing) who passed on around 1964 or so.


[text/html]


Back to: Top of message | Previous page | Main SAS-L page