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 (March 1997, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 11 Mar 1997 02:31:50 GMT
Reply-To:     lpogoda@AOL.COM
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         lpogoda@AOL.COM
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 the following:

PROC SQL; CREATE INDEX VAR1 ON YOURDATA (VAR1); QUIT;

DATA _NULL_; 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 END; END; STOP; RUN;

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 <5g1e23$1nf$1@gjallar.daimi.aau.dk>, jqrn@mi.aau.dk (Joern Lodahl) writes:

>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) >THEN...' ? > >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 :-) > >


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