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 (September 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 18 Sep 2007 08:19:46 -0500
Reply-To:   "data _null_," <datanull@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "data _null_," <datanull@GMAIL.COM>
Subject:   Re: How do I sort tokens in a variable
Comments:   To: Eric Hoogenboom <erichoogenboom@yahoo.com>
In-Reply-To:   <200709181223.l8IAm5Ug008300@mailgw.cc.uga.edu>
Content-Type:   text/plain; charset=ISO-8859-1

The Experimental in V9.1 SORTC call routine could be useful to your technique.

data work.token; infile cards dlm='+' dsd missover; array _t[5] $1 t1-t5; input _t[*]; call sortc(of _t[*]); sortedToken = catx('+', of _t[*]); *drop t:; datalines4; B+C+A D+A B ;;;; run; proc print; run;

On 9/18/07, Eric Hoogenboom <erichoogenboom@yahoo.com> wrote: > Kevin, > > Two possible solutions: > > 1. Split up your token in variables, put these variables into an array and > sort the array. Then glue the sorted vars. For a quicksort implementation > see Paul Dorfman's www2.sas.com/proceedings/sugi26/p096-26.pdf > > 2. Split up the token in observations. Sort the dataset and then put it > back together. See code below. > > data token; > input token $ 1-20; > datalines; > B+C+A > D+A > B > run; > > data token2 (keep=id tok); > set token; > length tok $ 1; > > id = _N_; * IDENTIFY THE SPLITTED TOKEN; > > do i=1 to (length(token)+1)/2; > tok = substr(token, 2*i-1, 1); > output; > end; > run; > > proc sort data=token2; > by id tok; > run; > > data token3 (keep=token); > set token2; > by id tok; > > length token $ 20; > > retain token; > > if first.id then token = tok; > else token = catx("+", token, tok); > > if last.id then output; > run; > > > Hth, > Eric >


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