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 (January 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 11 Jan 2006 15:53:49 -0500
Reply-To:     Ya Huang <ya.huang@AMYLIN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ya Huang <ya.huang@AMYLIN.COM>
Subject:      Re: question: assign tags to different groups of obs
Comments: To: shenyiyu@GMAIL.COM

Here is my version:

data xx; input Return Buy Sell; cards; 0.5 1 0 0.3 0 0 0.2 0 0 0.7 0 1 0.4 0 0 0.5 0 0 0.1 1 0 0.2 0 0 0.3 0 1 ;

data xx; set xx; retain f1 f2 f3; if buy then do; f1=1; f3+1; end; if sell then f1=0; f2=(buy or sell or f1); trade=f3*f2; if trade=0 then trade=.; drop f1 f2 f3; run;

proc print; run;

Return Buy Sell trade

0.5 1 0 1 0.3 0 0 1 0.2 0 0 1 0.7 0 1 1 0.4 0 0 . 0.5 0 0 . 0.1 1 0 2 0.2 0 0 2 0.3 0 1 2

HTH

Ya On Wed, 11 Jan 2006 12:10:30 -0800, Yiyu <shenyiyu@GMAIL.COM> wrote:

>I have a data set like this: > >Obs Return Buy Sell >1 0.5 1 0 >2 0.3 0 0 >3 0.2 0 0 >4 0.7 0 1 >5 0.4 0 0 >6 0.5 0 0 >7 0.1 1 0 >8 0.2 0 0 >9 0.3 0 1 >........................................ >so on. > >So I do trading, buy the stock and sell it later, now I want to give >each round of trade a number, as following: > >Obs Return Buy Sell Trade >1 0.5 1 0 1 >2 0.3 0 0 1 >3 0.2 0 0 1 >4 0.7 0 1 1 >5 0.4 0 0 >6 0.5 0 0 >7 0.1 1 0 2 >8 0.2 0 0 2 >9 0.3 0 1 2 >........................................ > >I buy the stock at Obs = 1 and sell it at obs=4, so 1 -4 are 1st trade >and all have Trade = 1 >I buy the stock at obs = 7 and sell it at obs = 9 , so 7-9 are 2nd >trade and all have Trade = 2; > >obs 5-6 are not in the trade so they have trade = missing. > > >How to code it? >Thank you very much > >Yiyu


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