Date: Mon, 16 Jul 2001 08:21:48 -0700
Reply-To: "Terjeson, Mark" <TerjeMW@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <TerjeMW@DSHS.WA.GOV>
Subject: Re: reading in a record with undetermined lines
Content-Type: text/plain; charset=us-ascii
Hi,
One of the many approaches could be:
data sample;
input @1 varname $
@11 value $
;
cards;
Cust : John
Acct : 111
Amt : $150
Amt2 : $40
Cust : Jeff
Acct : 458
Amt : $450
Cust : Kim
Acct : 784
Amt : $214
Amt2 : $54
;
run;
data table1(keep=cust acct amt);
retain cust ' '
acct ' '
;
set sample;
if varname eq 'Cust' then cust = value;
if varname eq 'Acct' then acct = value;
if varname eq: 'Amt' then
do;
amt = value;
output;
end;
run;
Note: The "eq:" is a "starts with" comparison operator.
Note: The "retain" causes the listed variables to retain
their value across observations.
Hope this is helpful,
Mark Terjeson
Washington State Department of Social and Health Services
Division of Research and Data Analysis (RDA)
mailto:terjemw@dshs.wa.gov
-----Original Message-----
From: lebeau [mailto:lebeau777@HOTMAIL.COM]
Sent: Sunday, July 15, 2001 10:21 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: reading in a record with undetermined lines
I need to read in records that don't all have the same number of variables
over more than 1 line. Each variable has a label and a new record should
starts when I read a certain variable (Cust :)
ex.
Cust : John
Acct : 111
Amt : $150
Amt2 : $40
Cust : Jeff
Acct : 458
Amt : $450
Cust : Kim
Acct : 784
Amt : $214
Amt2 : $54
Problem is if I read in like:
input @11 var1 $5 /
@11 var2 $5 /
@11 var3 $5 /
@11 var4 $5 ;
I lose the Kim record because it only has 3 variables to the record.
Anything I try I lose records.
Question is, how do you read in the records to make a one line per record
flat file when you don't know how many lines a record (in the input file).
Each record begins with Cust : .