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 (August 2000, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 25 Aug 2000 16:57:39 -0400
Reply-To:   Edward Heaton <HEATONE@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Edward Heaton <HEATONE@WESTAT.COM>
Subject:   Multiple Sorts in One Data Set
Content-Type:   text/plain; charset="iso-8859-1"

Hi, all. I have a need to sort fifty different portions of a data set by different sort variables. That is, the data set (81,289 observations) contains variables * Strat (values in {1,2,3,...,50}), * Urban (values in {1,2,3,4}), * OERegion (values in {1,2,3,4}), and * Rand (values in real number system such that 0 < Rand < 1). I want the following order: * 1st the observations where Strat eq 1, ordered by Urban, then by Rand within Urban; * 2nd the observations where Strat eq 2, ordered by Urban, by OERegion within Urban, and by Rand within OERegion; * 3rd the observations where Strat eq 3, ordered by Urban, then by Rand within Urban; * 4th the observations where Strat eq 4, ordered by Urban, then by Rand within Urban; * etc. through * 16th the observations where Strat eq 16, ordered by Rand; * etc. through * 49th the observations where Strat eq 49, ordered by Urban, then by Rand within Urban; * 50th the observations where Strat eq 50, ordered by Rand.

I do NOT want to create 50 independently sorted data sets and then combine them in a data step with a set statement.

I tried:

Proc sql ; Create table OrderedFrame as select * from Frame where (Strat eq 1) order by Urban, Rand union corr select * from Frame where (Strat eq 2) order by Urban, OERegion, Rand union corr select * from Frame where (Strat eq 3) order by Urban, Rand union corr select * from Frame where (Strat eq 4) order by Urban, Rand union corr etc. through union corr select * from Frame where (Strat eq 4) order by Rand union corr etc. through union corr select * from Frame where (Strat eq 49) order by Urban, Rand union corr select * from Frame where (Strat eq 50) order by Rand ; Quit ; Data OrderedFrame ; Set OrderedFrame ; SeqNo = _n_ ; Run ;

But this did not work. I got a message that said that SAS did not recognize ORDERED. At a friend's suggestion I tried Create table OrderedFrame as select * from ( select * from Frame where (Strat eq 1) order by Urban, Rand union corr select * from Frame where (Strat eq 2) order by Urban, OERegion, Rand etc. ) ; but this gave the same error. I tried it without the parentheses around the boolean expression (again, at someone's suggestion) with no difference. Does anyone out there have a nice way to do this?

Thanks in advance, Ed

Edward Heaton, SAS Senior Statistical Systems Analyst, Westat (An Employee-Owned Research Corporation), 1550 Research Boulevard, Room 2018, Rockville, MD 20850-3159 Voice: (301) 610-4818 Fax: (301) 294-3992 mailto:heatone@westat.com http://www.westat.com


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