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 (July 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 15 Jul 1999 10:45:15 -0400
Reply-To:     "Fehd, Ronald J." <rjf2@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Fehd, Ronald J." <rjf2@CDC.GOV>
Subject:      Re: Sorting a macro list
Content-Type: text/plain; charset="iso-8859-1"

From: John Megargee [mailto:johnmegargee@NETSCAPE.NET] /I have a blank-separated list of up to 100 valid v6 SAS names that in general /don't follow any particular pattern The whole list is assigned to a macro /variable, for instance (these are just random words for tests):

/%LET LIST = /SG FJLKDSN GEWO OPITHUI GJSERO TNJEOWIJ TW9345Y TWES SDJGJSRL NWOITJN RET /ORA47Q3 Y94 Z Q374R R462QTQ;

/Is there a macro function that would return the same list in a sorted order /like %LET SORTLIST = %SORT(&LIST)? I know how to do it with SORT or SQL but it /_must_ be done in a macro. It would be also nice to be able to sort the list /ascending or descending and remove duplicates if necessary. I've tried bubble /and insertion sorts but they seem to run forever. Any help is really /appreciated.

LOL writing a bubble -- or any other type -- sorting routine in the macro language?! gimme a break, there's a round flat thing with a hole in the middle right in front of you. I recommend using SAS to do the sorting because that is what it can do well.

%macro sortlist(list); %local I DIM_ITEM;%LET DIM_ITEM = 100; %DO I = 1 %TO &DIM_ITEM;%local ITEM&I.;%END; %ARRAY(ITEM,&LIST.);run; data LIST; length Item $8; %DO I = 1 %TO %DIM_ITEM; Item = "&&ITEM&I.";output;%END; stop; proc SORT data = LIST; by Item; %*turn data set back into mac-var: an exercise for the macro-literate; %MEND;

Ron Fehd the right tool maven CDC Atlanta GA author of the Very Large Macro %ARRAY see SUGI 22 Proceedings;


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