Date: Tue, 18 Sep 2007 08:19:46 -0500 "data _null_," "SAS(r) Discussion" "data _null_," Re: How do I sort tokens in a variable To: Eric Hoogenboom <200709181223.l8IAm5Ug008300@mailgw.cc.uga.edu> 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