BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

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
1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

 

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;

 

Thanks,
Suryakiran

View solution in original post

5 REPLIES 5
Reeza
Super User

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.

SuryaKiran
Meteorite | Level 14

 

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;

 

Thanks,
Suryakiran
ChrisBrooks
Ammonite | Level 13

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;
hhchenfx
Barite | Level 11

Thank you,

With all kind of option, SAS should make it simpler 🙂

HHC

Ksharp
Super User

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;

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1002 views
  • 2 likes
  • 5 in conversation