Date: Thu, 28 Oct 2004 15:49:58 -0400
Reply-To: Nathaniel_Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject: Re: reading heirarchical files
Content-type: text/plain; charset=US-ASCII
Of the several replies that I have seen, I prefer Jeff's since it requires
only one pass at the input file; however, I suggest adding keep statements
to the three output file names since each file has different groups of
variables. E.g.
Data bca.alias (keep = record_type person_num last_name first_name
Middle_name QID_FLG )
bca.otherDOB (keep = etc
Nat Wooding
Jeff Voeller
<Jeff.Voeller@MCI To: SAS-L@LISTSERV.UGA.EDU
.COM> cc:
Sent by: "SAS(r) Subject: Re: reading heirarchical files
Discussion"
<SAS-L@LISTSERV.U
GA.EDU>
10/28/04 03:32 PM
Please respond to
Jeff Voeller
Untested, but I think you're looking for some variation on the below. You
really don't need to read through the file three different times, you can
just read it once and output the appropriate records to the appropriate
datasest. You'll also want to have (keep=) dataset options for each output
dataset.
libname BCA 'M:\BCA04';
data bca.alias
bca.otherDOB
bca.convicthead;
infile 'M:\BCA04\public.dat' missover truncover;
input record_type $ 2.@;
if record_type = '02' then do;
input record_type $ 2. person_num $ 6. last_name $
30. first_name $ 30. Middle_name $ 30. QID_FLG $ 1.;
output bca.alias;
end;
else if record_type = '03' then do;
input record_type $ 2. person_num $ 6. DOB $ 8.;
output bca.otherDOB;
end;
else if record_type = '04' then do;
input record_type $ 2. person_num $ 6. convictnum 3.
Agcycode $ 9. CntrlAgcy $ 65. casenum $ 12.
crtdispdate MMDDYY8. crtagcycode $ 9. crtagncy $ 65.
assgncustagy $ 65. assprobagny $ 65.;
output bca.convicthead;
end;
run;
If you really, really, really want to read through the input file multiple
times, just don't make your "if record_type" tests into DO loops...just
leave them as "if record_type='whatever'" and any other record type will
not
be output.
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of ron
nixon
Sent: Thursday, October 28, 2004 12:20 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: reading heirarchical files
I have a heirarchical file where the first two
characters determines the type of file. For example,
my data looks like this:
010001 Arrest xxxx xxxxxx
020001 Calls xxxxx xxxxxx
030002 xxxx xxxxxx xxxxxx
So if the first two characters are 01 then if should
input just the obsevations on that line and so on. For
'02' then it should input the observation for that
line. The problem is that all observations are read
into the files not matter what. I can't figure out how
to read in just the observations for a particular
file. Can someone tell me what I'm missing?
Here's what my code looks like:
libname BCA 'M:\BCA04';
data bca.alias;
infile 'M:\BCA04\public.dat'missover truncover;
input record_type $ 2.@;
if record_type = '02' then do;
input record_type $ 2. person_num $ 6. last_name $
30. first_name $ 30. Middle_name $ 30. QID_FLG $ 1.;
end;
output;
run;
data bca.otherDOB;
infile 'M:\BCA04\public.dat'missover truncover;
input record_type $ 2.@;
if record_type = '03' then do;
input record_type $ 2. person_num $ 6. DOB $ 8.;
end;
output;
run;
data bca.convicthead;
infile 'M:\BCA04\public.dat' missover truncover;
input record_type $ 2.@;
if record_type = '04' then do;
input record_type $ 2. person_num $ 6. convictnum 3.
Agcycode $ 9. CntrlAgcy $ 65. casenum $ 12.
crtdispdate MMDDYY8. crtagcycode $ 9. crtagncy $ 65.
assgncustagy $ 65. assprobagny $ 65.;
end;
output;
run;
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail