Hi Everyone,
I am not sure what to do with the sort below.
I just sort by var (character) and the result is:
I try to compress ( var, ". -") to eliminate these character and the sort on the variable but still doesn't help.
Can anyone tell me how to move TestPros in from of the TREX?
Many thanks.
HHC
SES |
TREX- OII |
TREX- TI |
TestPros |
VA-SP |
Hi,
A primary linguistic collation rule is to treat alphabetic characters equally regardless of case.
proc sort data=need sortseq=linguistic(strength=primary);;
by val ;
run;
Try the CASEFIRST option?
By default capital letters sort before lower case.
If case doesn't matter for order, but does matter for appearance, then I would consider creating a duplicate variable that is all one case and sorting by that.
You should also look into the Linguistic/Collating options to change the order.
But, if none of those work and you need a custom order, a format is the best approach, but it's essentially manual at that point.
Hi,
A primary linguistic collation rule is to treat alphabetic characters equally regardless of case.
proc sort data=need sortseq=linguistic(strength=primary);;
by val ;
run;
If I understand you correctly you simply want TestCase to appear after SES and before TREX- Oil
Assuming I'm correct this should give you what you need
data have;
length test $8;
infile datalines;
input test;
datalines;
SES
TREX- OII
TREX- TI
TestPros
VA-SP
run;
proc sql;
create table want
as select test
from have
order by lowcase(test);
quit;
Thank you,
With all kind of option, SAS should make it simpler 🙂
HHC
Maybe the following code could get you what you want.
data have;
length test $8;
infile datalines;
input test;
datalines;
SES
TREX- OII
TREX- TI
TestPros
VA-SP
run;
proc sql;
create table want
as select test
from have
order by compress(test, ,'ka');
quit;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.