Date: Tue, 15 Oct 2002 18:49:05 -0400 Sigurd Hermansen "SAS(r) Discussion" Sigurd Hermansen Re: weird sort problem | programming challenge To: "evan.cooch@NOSPAMCORNELL.EDU" text/plain; charset="iso-8859-1"

Your array rotation problem has a fairly standard solution in a qualified off-set of an array index: data _null_; call symput('_nobs',nobs); stop; set xx nobs=nobs; run; %macro shift(_trace=ON); data xx (drop=i j); array aa(&_nobs.) _temporary_; do i=1 by 1 until(end); set xx end=end nobs=_nobs; aa((i ne _nobs)*i + 1)=a; end; do j=1 to _nobs; a=aa(j); output; end; stop; run; %if (&_trace.=ON) %then %do; proc print; run; %end; %mend shift; %shift %shift %shift %shift

One odd note: has anyone seen this Note?

NOTE: Line generated by the invoked macro "SHIFT". 1 data _null_; call symput('_nobs',nobs); stop; set xx nobs=nobs; run; ---- 546

NOTE 546-185: The variable nobs may be uninitialized.

Sig

-----Original Message----- From: evan.cooch@NOSPAMCORNELL.EDU [mailto:evan.cooch@NOSPAMCORNELL.EDU] Sent: Tuesday, October 15, 2002 5:01 PM To: SAS-L@LISTSERV.UGA.EDU Subject: weird sort problem | programming challenge

Must be late in the day, or the beer has run otu. One or the other ;-)

Suppose you have a data set, containing the following simple oridnal sequence of numbers:

1 2 3 4

What I'm try to do is sequentially generate what I'll call 'frame-shift' sorts of these numbers:

4 1 2 3

then

3 4 1 2

then

2 3 4 1