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

Hi,

 

I am looking for a way to convert letters to their alphabetic rank. I know that the RANK function can convert the letter to its ASCII ranking but I am looking for a way to do the reverse function of that.

 

I have a dataset that looks like this (every number is in a separate variable): 

 

var1var2var3var4
1234
26252423

...

 

Here is what I want:

 

var1var2var3var4
abcd
zyxw

...

 

 

 

Can anyone help me with that?

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You can use the BYTE() function. Capital letters start at 65 and lower case start at 97.

var1char = byte(var1+96);

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Use the byte() function.

data _null_;
  A= 1; B=byte(96+A); putlog B=;
  A=26; B=byte(96+A); putlog B=;
run;

B=a
B=z

 

 

Reeza
Super User
You can use the BYTE() function. Capital letters start at 65 and lower case start at 97.

var1char = byte(var1+96);
SuryaKiran
Meteorite | Level 14

You can also use a format.

 

proc format;
value a2z 	1="a" 2="b" 3="c" 4="d" 5="e"
			6="f" 7="g" 8="h" 9="i" 10="j" 
			11="k" 12="l" 13="m" 14="n" 15="o"
			16="p" 17="q" 18="r" 19="s" 20="t" 
			21="u" 22="v" 23="w" 24="x" 25="y" 26="z";
run;


data have;
format i a2z.;
do i=1 to 26;
output;
end;
run;
Thanks,
Suryakiran
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
  • 3 replies
  • 2913 views
  • 2 likes
  • 4 in conversation