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

How to sort the variable "rating" so that the value "AA" is first than "A"? Because my results are coming out like this:

A01

A02
A03

AA01

AA02
AA03
B01
B02
B03
C01
C02
C03

 

CODE:

proc sql;

create table resul_perf as select

date,

varl,

qtde_def,

case when def = 1 then sum(qtde_def)-qtde_def end as qtde_good,

sum(qtde_def) as qtde_total

from perf

group by DATE,variavel

having def = 1;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Thalitacosta WHY do you want to sort this way?

In the collating sequence digits come before characters and though A0 comes before AA. This is not only with SAS the case - like copy/paste your codes into Excel and sort there. You will get the same result.

I'm sure with a bit of effort some code could be written to arrange the data the way you have in mind. But why would you do that given that "nothing else" would sort the data this way.

View solution in original post

5 REPLIES 5
Thalitacosta
Obsidian | Level 7

rating = varl

Thalitacosta
Obsidian | Level 7

variável = varl

Thalitacosta
Obsidian | Level 7

How to sort the variable "rating" so that the value "AA" is first than "A"? Because my results are coming out like this:

A01

A02
A03

AA01

AA02
AA03
B01
B02
B03
C01
C02
C03

 

CODE:

proc sql;

create table resul_perf as select

date,

rating as varl,

qtde_def,

case when def = 1 then sum(qtde_def)-qtde_def end as qtde_good,

sum(qtde_def) as qtde_total

from perf

group by date,varl

having def = 1;

run;

Patrick
Opal | Level 21

@Thalitacosta WHY do you want to sort this way?

In the collating sequence digits come before characters and though A0 comes before AA. This is not only with SAS the case - like copy/paste your codes into Excel and sort there. You will get the same result.

I'm sure with a bit of effort some code could be written to arrange the data the way you have in mind. But why would you do that given that "nothing else" would sort the data this way.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 692 views
  • 2 likes
  • 3 in conversation