Date: Tue, 11 Mar 1997 02:31:50 GMT
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
Organization: AOL http://www.aol.com
Subject: Re: for i in dataset do...
Let me make sure I understand the problem.
You have a dataset. On each observation of this dataset is a numeric variable.
The value of the variable is somewhere between a known minimum and maximum.
Any given value can be repeated on several observations, and not all possible
values may be used.
You want to do some processing for all used values of the variable. Such
processing is to happen once for each distinct value.
OK so far?
I know I'm missing something, because you have all distinct values in your
simple, one variable table, yet for some reason processing that table doesn't
give you what you want.
Anyway, you might consider indexing your full dataset by the variable in
question, and then SETting the dataset using the KEY option. Something like
CREATE INDEX VAR1 ON YOURDATA (VAR1);
MIN = your_minimum_value;
MAX = your_maximum_value;
DO VAR1 = MIN TO MAX;
SET YOURDATA KEY = VAR1;
IF _IORC_ = 0 THEN DO;
your processing here
I haven't tested the code, and more to the point I don't have a manual handy,
so check the create index statement syntax.
In article <email@example.com>, firstname.lastname@example.org (Joern Lodahl)
>I have a general problem, which I have tried to address with and
>without macro programming. Now I hope for some advice from you.
>I have a variable 'var1' taking values 1, 2 and 4 say. (Generally the
>values of 'var1' are not known in advance, only the minimum and maximum.)
>I have a few lines code which I want to execute for each of the actual
>values of 'var1'. In pseudo code this could look something like
> %do i=&min to &max; %put i;
>But this will also be executes for not realised values of 'var1' which
>I dont want to. (In this example i=3 will be nonsence). Would it be
>possible to create a &list=1 2 4 so I can test for 'IF i IN (&list)
>Another approach I have tried is to construct a simple dataset
>with one variable 'table' taking the unique values of 'var1' but then
>I need a way to test whether or not &i is one of the values of 'table'
>(and therefore of 'var1')...
>As you see I am a bit confused about this, hopefully I didnt confuse
>you too :-)