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

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
Rhodochrosite | Level 12

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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