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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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