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 (July 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 4 Jul 2006 12:37:21 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: This code does not run!

On Mon, 26 Jun 2006 02:35:42 -0700, abose <hirak99@GMAIL.COM> wrote:

>Still think it's kinda nuisance... I thought I could just code the >following single line: > >if 442 in >(ID_SRCE,LIST6RCS,LIST3RCS,LIST4RCS,LIST8RCS,LIST9RCS,LIST1RCS,LIST5RCS) >then VL=' '; > >But now have to I code it like: > >array VLListCodes ID_SRCE LIST6RCS LIST3RCS LIST4RCS LIST8RCS LIST9RCS >LIST1RCS LIST5RCS LIST7RCS; >if VL='Y' then do; > do i=1 to dim(VLListCodes); > if VLListCodes(i)=442 then VL=' '; > end; >end; >drop i;

You can dispense with one DO/END:

data _null_; array VLListCodes ID_SRCE LIST6RCS LIST3RCS LIST4RCS LIST8RCS LIST9RCS LIST1RCS LIST5RCS LIST7RCS; input VL $ LIST1RCS; if VL='Y' then do i=1 to dim(VLListCodes); if VLListCodes(i)=442 then VL=' '; end; put _N_= VL=; cards; Y 441 Y 442 ;

Results:

_N_=1 VL=Y _N_=2 VL=

In Version 9, the loop can be replaced with the IN operator:

data _null_; array VLListCodes ID_SRCE LIST6RCS LIST3RCS LIST4RCS LIST8RCS LIST9RCS LIST1RCS LIST5RCS LIST7RCS; input VL $ LIST1RCS; if VL='Y' and 442 in VLListCodes then VL=' '; put _N_= VL=; cards; Y 441 Y 442 ;

> > >Chang Chung wrote: >> On Fri, 23 Jun 2006 06:16:11 -0700, abose <hirak99@GMAIL.COM> wrote: >> >> >data test; >> >x=1; >> >y=2; >> >z=1 in (x,y); >> >run; >> > >> >---------- >> >upshot - the in clause expects constants only! pretty counterintuitive >> >for me. >> >> hi, >> >> Counterintuitive it may be, but is clearly documented. >> >> I can think of two reasons why this may be the case: >> (1) si knows that we sas users are not the smartest bunch. So, this may be >> by design, in order to prevent us from shooting our own foot. The data step >> has an implicit loop over ovservations. You may not know this and get >> surprised that the values of x and y can be changed an observation to another; >> (2) for efficiency and execution speed. If only the constants, then you can >> set up a hash table or an array to be looked up quickly at the compile time >> and just use it over and over. If it has variables, then you have to set >> this kind of data structure for each time when the step processes a new >> observation, which may take much much longer time. >> >> By the way, the "in" here is not a clause, but an operator. Used in numeric >> comparisons, it can also take range(s) such as: >> >> y = x in (1:10); >> >> Of course, the range does not work in the where statement or in the where >> clause in proc sql. This is also understandable, if you dig that the data >> step expression, the where statement expression, and expressions used in the >> proc sql where clause are all different things. >> >> Cheers, >> Chang


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