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 (April 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 24 Apr 2005 16:47:50 -0700
Reply-To:   Yiyu <shenyiyu@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Yiyu <shenyiyu@GMAIL.COM>
Organization:   http://groups.google.com
Subject:   A condition comparison with previous value
Comments:   To: sas-l@uga.edu
Content-Type:   text/plain; charset="iso-8859-1"

Here is one problem troubling me for long time....

What I want to do is this: Suppose following is the data:

obs P MaxP b_signal

1 10 11 0 2 12 12 1 3 11 12 0 4 11 12 0 5 9 12 0 6 8 12 0

You see at the obs 2 P >= MaxP, which triggers the b_signal, indicating a buy action, now my rule is keep holding what I have bought at obs 2 until price has dropped 20%: P < 0.8 MaxP, this will happen at obs 5. So I want to create a dummy 'Holding' indicating the period I hold what I have bought, it should look like this:

obs P MaxP b_signal Hold

1 10 11 0 0 2 12 12 1 1 3 11 12 0 1 4 11 12 0 1 5 9 12 0 0 6 8 12 0 0

You see the value of Hold depends on three values: the previous value of itself, the previous value of b_signal, and the comparison between P and MaxP. How to do it in a Data step? or SQL? Seems quite chanllenging.

Thank you very much

Yiyu


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