Date: Thu, 17 Oct 2002 07:50:03 -0400
Reply-To: john.hixon@KODAK.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: john.hixon@KODAK.COM
Subject: weird sort problem | programming challenge
Content-type: text/plain; charset=us-ascii
/*
I get SAS-L in digest mode and often I am so busy that I go days without
reviewing the digests (and, indeed, often I delete 10-20 digests unread).
So, forgive my tardiness in replying to this post, but, I did not
see any suggestions to use Proc Plan, and it is a simple way to
achieve what Evan requested.
Here is Evan's original question:
>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
>leading back to
>1
>2
>3
>4
>Any ideas how to do this (without using SQL)? I'm stuck...
There were several good answers supplied using the data step or some
macros.
But, if you have SAS STAT, then you can do this very simply using
Proc Plan. Proc Plan has many other features for generating permutations
and combinations. These are very helpful in coming up with DOEs.
As an aside, I am also using Proc Plan as I SLOWLY write a set
of macros to enhance the functionality of Proc PLS. (I was guided
to Proc Plan thanks to a tip from Randy Tobias.) Creating the PLS
Macros is a labor of love, but I'm doing it on my own time at home,
and my (very pregnant --- hooray!!!) wife has become highly intolerant
of me spending much time doing coding at home. :-)
So, the macros won't be ready till, oh, maybe late Spring 2003?
Of cousre, I'll share them when they are done.
Um, sorry for the diversion.
Below is the simple Proc Plan code to generate what Evan requested.
Be sure to look up the documentation for Proc Plan. It is very
handy for things like this.
*/
* "Frame Number=13" indicates "Repeat 13 times";
* "a=4 cyclic" indicates, give me 1,2,3,4 then 2,3,4,1 then etc etc.;
proc plan;
factors FrameNumber=13 ordered a=4 cyclic ;
output out=desired;
run;
proc print data=desired;
run;
/*
This produces the following output:
Frame
Obs Number a
1 1 1
2 1 2
3 1 3
4 1 4
5 2 2
6 2 3
7 2 4
8 2 1
9 3 3
10 3 4
11 3 1
12 3 2
13 4 4
14 4 1
15 4 2
16 4 3
17 5 1
18 5 2
19 5 3
20 5 4
21 6 2
22 6 3
23 6 4
24 6 1
25 7 3
26 7 4
27 7 1
28 7 2
29 8 4
30 8 1
31 8 2
32 8 3
33 9 1
34 9 2
35 9 3
36 9 4
37 10 2
38 10 3
39 10 4
40 10 1
41 11 3
42 11 4
43 11 1
44 11 2
45 12 4
46 12 1
47 12 2
48 12 3
49 13 1
50 13 2
51 13 3
52 13 4
HTH,
Best regards,
John Hixon
Eastman Kodak Company
Rochester, NY USA
585-477-1984