DATA Step, Macro, Functions and more

Sort issue

Accepted Solution Solved
Reply
Super Contributor
Posts: 412
Accepted Solution

Sort issue

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

Accepted Solutions
Solution
2 weeks ago
Frequent Contributor
Posts: 136

Re: Sort issue

 

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


All Replies
Super User
Posts: 19,815

Re: Sort issue

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.

Solution
2 weeks ago
Frequent Contributor
Posts: 136

Re: Sort issue

 

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
Super Contributor
Posts: 440

Re: Sort issue

Posted in reply to SuryaKiran

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;
Super Contributor
Posts: 412

Re: Sort issue

Posted in reply to SuryaKiran

Thank you,

With all kind of option, SAS should make it simpler Smiley Happy

HHC

Super User
Posts: 10,028

Re: Sort issue

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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