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):
var1 | var2 | var3 | var4 |
1 | 2 | 3 | 4 |
26 | 25 | 24 | 23 |
...
Here is what I want:
var1 | var2 | var3 | var4 |
a | b | c | d |
z | y | x | w |
...
Can anyone help me with that?
Thank you!
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
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.