max of character

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

max of character

by ranking:

C>B>A>null

 

any proc sql code to get the max of the character?

 

i can get max of a numeric value, how to apply the same for character?

 

Thanks


Accepted Solutions
Solution
‎06-25-2017 09:34 PM
PROC Star
Posts: 1,561

Re: max of character

[ Edited ]

That's a sad state of affairs. See https://communities.sas.com/t5/SASware-Ballot-Ideas/create-string-summary-functions/idi-p/288035 and vote.

In the meantime, you can use   MAX=byte(max(rank(VAR1),rank(VAR2)))  since you only have one letter (and if you are not on mainframe).

View solution in original post


All Replies
PROC Star
Posts: 551

Re: max of character

You can tie each lettet to a new numeric variable with the desired ranking such that if var = 'A' then rankvar = 1; if var = 'B' then rankvar = 2; and so on.

Solution
‎06-25-2017 09:34 PM
PROC Star
Posts: 1,561

Re: max of character

[ Edited ]

That's a sad state of affairs. See https://communities.sas.com/t5/SASware-Ballot-Ideas/create-string-summary-functions/idi-p/288035 and vote.

In the meantime, you can use   MAX=byte(max(rank(VAR1),rank(VAR2)))  since you only have one letter (and if you are not on mainframe).

PROC Star
Posts: 1,230

Re: max of character

If you want aggregate max, i.e. the max of values found in a column, you can use the MAX() function the same way you would with a numeric variable.  If you want to find the the max of values within a row, you can't use the MAX() function, but you can use the MAX operator.

 

data have;
  input x $1. @3 y $1.;
cards;
A Q
C Q
B A
;
run;

proc sql;
  select max(x) as mymax from a;
quit;

mymax
C


proc sql;
  select x max y as mymax from have;
quit;

mymax
Q
Q
B
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 132 views
  • 0 likes
  • 4 in conversation