Date: Fri, 24 Sep 2010 11:07:03 -0400
Reply-To: sas quest <sasquest@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: sas quest <sasquest@GMAIL.COM>
Subject: Re: Using retain
In-Reply-To: <AANLkTi=72RpkrxJ9fBdJipPj2wbRvgO87aENEbhR_Y9L@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Joe,
your suggested change doesnt work.since i want to retain last value of type
so that i can add it up to get continuous values for each sub.
thanks
On Fri, Sep 24, 2010 at 10:55 AM, Joe Matise <snoopy369@gmail.com> wrote:
> If you use 'if first.sub' instead of if type = 'A' then it should work as
> you want.
>
> -Joe
>
>
> On Fri, Sep 24, 2010 at 9:54 AM, sas quest <sasquest@gmail.com> wrote:
>
>> hi ,
>> my code fails as soon as sub changes to 2.
>> Art's code works ..but i wanted something more general without referring
>> to
>> type='A',since i might anticipate a variety of types.
>>
>> Thanks
>>
>> On Fri, Sep 24, 2010 at 10:47 AM, Arthur Tabachneck <art297@netscape.net
>> >wrote:
>>
>> > I think that you are trying to achieve the following:
>> >
>> > data have;
>> > input sub type $ val;
>> > cards;
>> > 1 A 20
>> > 1 A 30
>> > 1 A 36
>> > 1 A 41
>> > 1 B 1
>> > 1 B 5
>> > 1 B 11
>> > 1 B 19
>> > 2 A 12
>> > 2 A 20
>> > 2 A 29
>> > 2 A 31
>> > 2 B 3
>> > 2 B 10
>> > 2 B 11
>> > ;
>> > run;
>> >
>> > data want;
>> > set have;
>> > retain val_ 0;
>> > if type eq 'A' then do;
>> > val_=val;
>> > n_val=val;
>> > end;
>> > else n_val=val_+val;
>> > drop val_;
>> > run;
>> >
>> > HTH,
>> > Art
>> > ---------
>> > On Fri, 24 Sep 2010 10:36:59 -0400, Sas Quest <sasquest@GMAIL.COM>
>> wrote:
>> >
>> > >data have;
>> > >input sub type$ val;
>> > >cards;
>> > >1 A 20
>> > >1 A 30
>> > >1 A 36
>> > >1 A 41
>> > >1 B 1
>> > >1 B 5
>> > >1 B 11
>> > >1 B 19
>> > >2 A 12
>> > >2 A 20
>> > >2 A 29
>> > >2 A 31
>> > >2 B 3
>> > >2 B 10
>> > >2 B 11
>> > >run;
>> > >
>> > >Want:
>> > >Sub type val n_val
>> > >1 A 20 20
>> > >1 A 30 30
>> > >1 A 36 36
>> > >1 A 41 41
>> > >1 B 1 42
>> > >1 B 5 46
>> > >1 B 11 52
>> > >1 B 19 60
>> > >2 A 12 12
>> > >2 A 20 20
>> > >2 A 29 29
>> > >2 A 31 31
>> > >2 B 3 34
>> > >2 B 10 41
>> > >2 B 11 42
>> > >
>> > >my code:
>> > >
>> > >data want;
>> > >set have;
>> > >by sub type;
>> > >retain val_ 0;
>> > >n_val=val_+val;
>> > >/*f=first.type;
>> > >l=last.type;*/
>> > >if last.type then val_=val;
>> > >drop val_;
>> > >run;
>> > >
>> > >
>> > >What can be modified in my code to get the desired output?
>> > >
>> > >Thanks
>> >
>>
>
>
|