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 (August 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 22 Aug 2003 14:12:19 -0400
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: Help with SAS Code
Comments: To: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Content-Type: text/plain

Thanks, Howard. (Do you still want me in the code clinic?) Fortunately the mistake is easy to correct.

>%macro bs (n=10,var=price,v=temp); > %local i ; > %do i = 1 %to &n ; &v = dif&i ( &var ) ; > if sign = " " then > do ; > if &v > 0 then > sign='B'; > Else > if &v < 0 then > sign='S'; > end; > %end ; >%mend bs ;

IanWhitlock@westat.com

-----Original Message----- From: Howard Schreier [mailto:Howard_Schreier@ITA.DOC.GOV] Sent: Friday, August 22, 2003 1:31 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Help with SAS Code

This would generate code in which DIFn functions are invoked conditionally. That can be tricky.

On Fri, 22 Aug 2003 09:55:27 -0400, Ian Whitlock <WHITLOI1@WESTAT.COM> wrote:

>Dorian, > >Although it always guess work what is wanted when the specs are code >that you do not want, this may be what you want. > >%macro bs (n=10,var=price,v=temp); > %local i ; > %do i = 1 %to &n ; > if sign = " " then > do ; > &v = dif&i ( &var ) ; > if &v > 0 then > sign='B'; > Else > if &v < 0 then > sign='S'; > end; > %end ; >%mend bs ; > >data tradlse.vodtqe; > set tradlse.vodtqd; > If venue='dt' and tratype NE 'X' then > do; > If price-midq>0 then sign='B'; > If price-midq<0 then sign='S'; > %bs(n=10,var=price,v=temp) > end; >run; > >The main point here is to straighten out the use of macro and make sure that >DIF&I( PRICE ) occurs only once in the DATA step. Of course the code >is untested. > >A non-macro solution might be to keep a ring of the last 10 PRICE >values. > >IanWhitlock@westat.com >-----Original Message----- >From: Dorian Noel [mailto:d.noel@ISMACENTRE.RDG.AC.UK] >Sent: Thursday, August 21, 2003 4:19 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Help with SAS Code > > >Dear SAS Users; > >I have tried for several weeks to solve a SAS code (see below) I have >written to assign trades as either as buy ('B') or sell ('S') in >accordance with the Lee and Ready (1991) trade indicator algorithm. I >have also sought >the assistance of a SAS programmer at my university but with little >success to date. I urgently need to solve this piece of code in order >to complete an empirical paper. The code is as >follows: > >%macro dif(i,price); > dif&i(&price) >%mend; >data tradlse.vodtqe; >set tradlse.vodtqd; > If venue='dt' and tratype NE 'X' then do; > If price-midq>0 then sign='B'; > If price-midq<0 then sign='S'; > do while (sign=' '); > do i = 1 to 10; > if %dif(i,price) > 0 then do; > sign='B';goto out; end; > Else if %dif(i,price) < 0 then do; > sign='S'; goto out; end; > >end; >end; >out: >end; >run; > >Note, dif&n(&price) should resolve to be a DIF function on price. SAS >is interpreting it to be DIFI; do i = 1 to 10 is ignored. I have >written several versions of this base code but with little success. For >instance, I have re-written the macro dif(i, price) as follows: > >%macro dif(i,price); > %do; > %let n= %eval(&i); > dif&n(&price) > %end; >%mend; > >Can anyone tell me what is wrong with the SAS code. I would greatly >appreciate your assistance on this matter. > >Take care. > >Dorian


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