LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 2005, 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 Mar 2005 09:29:26 -0500
Reply-To:     SAS Bigot <SAS_Bigot@ML1.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         SAS Bigot <SAS_Bigot@ML1.NET>
Subject:      Re: sort.
In-Reply-To:  <200503221650.j2MGoIAE022611@listserv.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

Ya's solution below is the simplest and most elegant solution to your problem. By controlling the sort sequence with a CASE statement in the ORDER BY, you don't have to create a new dataset or modify the existing one with new sort vars. And if the dataset has a large number of obs, you'll benefit from improved runtimes, as well.

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ya Huang Sent: Tuesday, March 22, 2005 11:50 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: sort.

Try SQL:

data xx; input p vi $ do; cards; 1 3 40 1 b 20 1 4 40 2 b 20 2 3 60 2 2 45 ;

proc sql; select * from xx order by p, case when vi='b' then .Z else input(vi,best.) end ;

p vi do ---------------------------- 1 b 20 1 3 40 1 4 40 2 b 20 2 2 45 2 3 60

When vi='b', make it the samllest number in SAS, therefore, it will always come up first, the rest will be sorted based on their converted numeric value.

Kind regards,

Ya Huang

On Tue, 22 Mar 2005 10:13:53 -0500, Nishant Dholakia <nishant.dholakia@GMAIL.COM> wrote:

>Hi, >I have to create data set in which data is supposed to be like this > >p vi do >1 b 20 >1 3 40 >1 4 40 >2 b 20 >2 3 > >basically the sorting has to be done by p and vi. However the issue I am >facing is that vi is character values. using input i can convert the values >to numeric and sort however there is one value (b) that can not be >manipulated this way. the value b should always be the first for any p >value. >b is already present so I can not use the logic if first.p then vi =b; >Is there some way to do this. > >thanks


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