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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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.

ChrisNZ
Tourmaline | Level 20

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).

Quentin
Super User

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
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 16132 views
  • 1 like
  • 4 in conversation