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 21:57:01 -0800
Reply-To:     David L Cassell <davidlcassell@MSN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         David L Cassell <davidlcassell@MSN.COM>
Subject:      Re: IML Do Loop with If-Then-Else Bug?
In-Reply-To:  <200601112235.k0BLhorj021346@mailgw.cc.uga.edu>
Content-Type: text/plain; format=flowed

daniel.biostatistics@GMAIL.COM wrote: >I am trying to run the following code using IML Workshop: > >/* Define Vector as a 20X1 matrix */ >vector=j(20,1,.); > >/* Call random number generator to fill Vector, using a beta(5,10) >distribution */ >call randgen(vector,'beta',5,10); > >/* Define Vectorb as a 20X1 matrix */ >vectorb=j(20,1,.); > >/* Based on values of Vector, define Vectorb */ > >do i=1 to 20; > if 0<=vector[i]<0.1 then vectorb[i]=3; > else if 0.1<=vector[i]<0.2 then vectorb[i]=6; > else if 0.2<=vector[i]<0.3 then vectorb[i]=9; > else if 0.3<=vector[i]<0.4 then vectorb[i]=12; > else if 0.4<=vector[i]<0.5 then vectorb[i]=15; > else if 0.5<=vector[i]<0.6 then vectorb[i]=18; > else if 0.6<=vector[i]<0.7 then vectorb[i]=21; > else if 0.7<=vector[i]<0.8 then vectorb[i]=24; > else if 0.8<=vector[i]<=1 then vectorb[i]=27; >end; > > >Here is the problem: the values of Vectorb are off by 1. For instance, >Vector=0.5281253 is between 0.5 and 0.6 so Vectorb should be =18, but >it is =21. > >I have the same problem if I use PROC IML. However, if I create a >dataset with just Vector, and then use a datastep with the exact, >copy-pasted code, then I get the correct values for Vectorb. > >Has anyone encountered such a problem? Am I missing something crucial >about the way IML works?

I see that experts have already chimed in. Dale is right (as always) about the problem with the form

0.1 <= vector[i] < 0.2

As I recall, at one time, the DATA step did not recognize that structure either. It has been improved, while other components have not.

Now let me bring up the real reason I am writing in even after your problem has been answered. I think this would be even easier if you were doing it in a DATA step. You seem more comfortable with the structures in DATA steps, so it might be easier for you. Just use arrays in place of your vectors. Now you may have additional features that you wish to add, so IML may look more appealing than the DATA step, but I'd like you to think about it.

HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330

_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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