|
This is more obvious and you don't have to deal with the index being incremented past the loop exit
do I = 1 to dim(date-old);
do J = 1 to dim(date-old);*until matched dates;
if date-index(J) = date-old(I) then do;
date-new{J) = date-old(I);
school-new(J) = school-old(I);
leave;
end;
end;
end;
> Ron Fehd here(we(are)) maven
> -----Original Message-----
> From: Fehd, Ronald J. (CDC/OCOO/ITSO)
> Sent: Friday, April 06, 2012 12:35 PM
> To: 'SAS-L@LISTSERV.UGA.EDU'
> Subject: RE: Determining which element of an array has the desired value
>
> > From: Andrew Karp/Sierra Information Services
> > Sent: Friday, April 06, 2012 9:26 AM
> > To: SAS-L@LISTSERV.UGA.EDU; Daniel Nordlund
> > Subject: Re: Determining which element of an array has the desired
> > value
> >
> > Hi all...
> >
> > I really appreciate the time and effort several of you have put in to
> > answering my query, but I guess I was not clear on what I really need/want.
> >
> > The issue is that the degrees are not listed in the date order they
> > were granted in the source field (a text field in a university data
> > base). In my example I posted yesterday, the earliest degree earned
> > is the second of the three degree dates listed in the field.
> >
> > What I need is a way to assign to Degree_1 the *earliest* (in time)
> > degree earned that is listed in the source field and to Degree_2 the
> > "next" (in
> > time) degree the student earned and to degree_3 the "last" (or most
> > recent, in time) degree earned and to then assign to school_1 the name
> > of the school which granted the first degree (in time) they earned.
> >
> > Is there a solution to this problem using, perhaps, some aspect of the
> > ARRAY facility I can't conjure up at the moment?
> >
> > Thanks again,
> > Andrew
>
> Hi Andrew
>
> I see that most folks want to vertical the data, transpose and then flatten
>
> When I wrote up SAS implementations of Knuth's sorting algorithms
>
> http://www.sascommunity.org/wiki/Category:Knuth
>
> one of the things I learned was that one could use an array reference as the
> index of another array reference.
>
> i.e., in the distribution counting algorithm:
>
> Count{K{J}} + 1;
>
> it seems to me a solution will need these arrays date-old school-old
>
> date-index _temporary_
>
> date-new
> school-new
>
> the interesting part of this in-row processing is that the dates are not
> integers, thus not candidates for an array index.
>
> the problem is how to associate a date with an index value.
>
> the solution is something like:
> do I = 1 to dim(date-old);
> date-new(I) = (date-index(date-old(I)));
> school-new(I) = ...;
> end;
>
> I think sorting the date-old into the data-index array is straight-forward then
> you need to search the date-index for a match
>
> do I = 1 to dim(date-old);
> do J = 1 to dim(date-old);
> if date-index(J) = date-old(I) then leave;
> end;
> date-new{J) = date-old(I);
> school-new(J) = school-old(I);;
> end;
>
> Here is a reference on exiting loops and the index values to expect:
>
> http://www.sascommunity.org/wiki/Do_which_loop_until_or_while
>
> Ron Fehd we(are(here)) maven
|