Date: Tue, 29 Aug 2006 08:53:57 -0400
Reply-To: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Subject: Re: why doesnt this simple first. last. routine work
queanbeyan@hotmail.com wrote:
> Hi
>
> I am having one of those days where i left my mind at home in the rush
> to work.
>
> I cant quite get this simple longitudinal data problem to work.
You are looping over all bens,letr and entl, on each row.
The construct should be
myFlatteningArrayVariable[sequenceVariable] = SomeRowValue. I.e.
bens(period)=bentp;
letr(period)=letter;
entl(period)=amounts;
----------------------------------------
options obs=max;
data test_data;
infile datalines missover pad;
input @1 cust_id @3 bentp $3. @7 letter $1. @9 amounts @13 period;
datalines;
1 aaa a 10 1
1 bbb b 20 2
1 ccc c 30 3
2 aaa a 10 1
2 bbb b 20 2
2 ccc c 30 3
3 aaa a 10 1
3 bbb b 20 2
3 ccc c 30 3
;
run;
data check1;
array bens(3) $ benefit1-benefit3;
array entl(3) entitle1-entitle3;
array letr(3) $ letter1-letter3;
set test_data;
by cust_id;
retain benefit1 benefit2 benefit3 entitle1-entitle3 letter1-letter3;
if first.cust_id then do;
do i = 1 to 3;
bens(i)='';
entl(i)=.;
letr(i)='';
end;
end;
/* NO
do i = 1 to 3;
bens(i)=bentp;
letr(i)=letter;
entl(i)=amounts;
end;
*/
/* YES */
bens(period)=bentp;
letr(period)=letter;
entl(period)=amounts;
if last.cust_id then output;
run;
proc print;
run;
----------------------------------------
A DOW loop is often less coding, and does not use retains. Array resetting
and output is automatic as part of the implicit loop.
----------------------------------------
data check2;
array bens $ benefit1-benefit3;
array entl entitle1-entitle3;
array letr $ letter1-letter3;
do until (last.cust_id);
set test_data;
by cust_id;
bens(period)=bentp;
letr(period)=letter;
entl(period)=amounts;
end;
run;
----------------------------------------
Richard A. DeVenezia
http://www.devenezia.com/