Date: Wed, 16 Nov 2011 08:25:47 -0500 "Bian, Haikuo" "SAS(r) Discussion" "Bian, Haikuo" Re: first occurence and conditions within arrays To: tony tony text/plain; charset="us-ascii"

Tony, I hope this is what you want.

Data I_get; set I_have; array LDF{*}\$ dfm1-dfm4; array Lbal{*} bal1-bal4; do j=1 to dim(LDF); if LDF(j) ="y" then do; Def_month=j; Def_balance=Lbal(j); if def_balance<=100 and j>1 then do; def_balance=ifn(lbal(j-1)<=100,disc_amt,def_balance); end; leave; end; end;

Regards, Haikuo

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of tony tony Sent: Wednesday, November 16, 2011 7:26 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: first occurence and conditions within arrays

Hi Ya,

Thank you.

In this case we are not chekcing the lag of the first occurence of "Y". In the code we are only emphasizing at the point where first "Y" occured.

Just make the matter clear. I add sixth observation in the data and show you how the code impacts the results:-

Data I_have;input Dfm1\$ Dfm2\$ Dfm3\$ Dfm4\$ bal1 bal2 bal3 bal4 disc_amt; Datalines; y y y y 200 5 33 50 40 N N N y 100 44 22 24 50 N N N y 42 22 22 300 500 N N Y N 55 200 300 100 12 N N y y 500 99 15 400 14 N N N y 100 44 200 24 50 ; run;

The above data is exactly the same as previous one but I have added only one observation. In the sixth observation you would see that the first occurence of "Y" happens at variable Dfm4 and at that point variable bal4 is 24( which is smaller than 100) but then to fullfil the second argument that lag of first occurence should also have balance lower than 100,it is only than we can have Def_balance=disc_amt. if we observe the first lag, which in this case happens to be bal3 which is not lower than 100 therefore the Def_balance should be 24 not 50.But the code produces 50 for Def_balnce variable.

With lots of thanks in advance.

regards,

Tony

On Wed, Nov 16, 2011 at 5:03 AM, Ya Huang <ya.huang@amylin.com> wrote:

> Just add one more line, see below. > > On Wed, 16 Nov 2011 04:19:05 +0100, tony tony <tonysingsong@GMAIL.COM> > wrote: > > >Hi, > > > >I would be thankful if I could get help on: > > > >*Data:-* > > > >Data I_have;input Dfm1\$ Dfm2\$ Dfm3\$ Dfm4\$ bal1 bal2 bal3 bal4 disc_amt; > >Datalines; > >y y y y 200 5 33 50 40 > >N N N y 100 44 22 24 50 > >N N N y 42 22 22 300 500 > >N N Y N 55 200 300 100 12 > >N N y y 500 99 15 400 14 > >;run; > > > >*Goal:- *Record the first occurence of the "Y" in a separate varaible > >called Def_month from the series > >of the Variable/array called LDF,at the same point we take the > Def_balance, > >shown in the code below. > >To this extent I have completed the code. Now, if just before the first > >occurence and also at the first occurence of > >"Y" the series of bal variable represented through Lbal remains less than > >or equal to 100 then Def_balance should equal > >the variable disc_amt. > > > >*For example:-* > > > >For the first observation, first occurence of "Y" happens in Dfm1 > therefore > >Def_month gets the value of 1 and since it this occurence come from first > >variable > >so Def_balance=bal1 that is 200. > >For the second observation occurence of "Y" happens in Dfm4 therefore > >Def_month gets the value of 4 and since it this occurence comes from > fourth > >varialbe > >so Def_balance=bal4 that is 4.But since we want extra condition to be > >fullfiled as discussed above the Def_balance then should be 50, value from > >disc_amt( needed output).This happens because 24 and 22 in Dfm3 and Dfm4 > >respectively have value less than 100; > > > >*Data I_get;* > >set I_have; > >array LDF{*}\$ dfm1-dfm4; > >array Lbal{*} bal1-bal4; > >do j=1 to dim(LDF); > >if LDF(j) ="y" then do; > >Def_month=j; > >Def_balance=Lbal(j) > > if def_balance <=100 then def_balance=disc_amt; > > >leave; > >end; > >end; > > > >*Data I_wanna;* > >input Dfm1\$ Dfm2\$ Dfm3\$ Dfm4\$ bal1 bal2 bal3 bal4 disc_amt Def_month > >Def_balance; > >Datalines; > >y y y y 200 5 33 50 40 1 200 > >N N N y 100 44 22 24 50 4 50 > >N N N y 42 22 22 300 500 4 300 > >N N Y N 55 200 300 100 12 3 300 > >N N y y 500 99 15 400 14 3 14 > >;run; > ----------------------------------------- Email messages cannot be guaranteed to be secure or error-free as transmitted information can be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The Centers for Medicare & Medicaid Services therefore does not accept liability for any error or omissions in the contents of this message, which arise as a result of email transmission.

CONFIDENTIALITY NOTICE: This communication, including any attachments, may contain confidential information and is intended only for the individual or entity to which it is addressed. Any review, dissemination, or copying of this communication by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and delete and destroy all copies of the original message.

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