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?
Content-Type: text/plain; format=flowed
>I am trying to run the following code using IML Workshop:
>/* Define Vector as a 20X1 matrix */
>/* Call random number generator to fill Vector, using a beta(5,10)
>/* Define Vectorb as a 20X1 matrix */
>/* 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;
>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
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.
David L. Cassell
3115 NW Norwood Pl.
Corvallis OR 97330
Express yourself instantly with MSN Messenger! Download today - it's FREE!