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:23:11 -0400
Reply-To:   Eric Hoogenboom <erichoogenboom@YAHOO.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Eric Hoogenboom <erichoogenboom@YAHOO.COM>
Subject:   Re: How do I sort tokens in a variable

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