LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 16 Nov 2011 13:25:59 +0100
Reply-To:     tony tony <tonysingsong@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         tony tony <tonysingsong@GMAIL.COM>
Subject:      Re: first occurence and conditions within arrays
Comments: To: Ya Huang <ya.huang@amylin.com>
In-Reply-To:  <201111160403.pAFKc9Bk031624@wasabi.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

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; >


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