将数字转换为基于基数 36 的字母数字值 [英] Convert numeric into an alphanumeric value based on radix 36

查看:39
本文介绍了将数字转换为基于基数 36 的字母数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 $HEX 格式很容易将数字转换为基于 SAS 中基数 16 的字母数字值.现在我正在寻找一种简单的方法来使用基数 36(10 个数字和 26 个字母)来做到这一点.

It is easy to transform a number into a alphanumeric value based on radix 16 in SAS by using the $HEX format. Now i'm looking for an easy way to do this with radix 36 (10 numerals & 26 letters).

示例:

  • 100 -> '2s'
  • 2000 -> '1jk'
  • 30000 -> 'n5c'
  • 400000 -> '8kn4'

在 Java 中,您可以通过 Integer.toString(mynumber, 36) 执行此操作.任何想法如何在 SAS Base 中做到这一点?

In Java you can do this by Integer.toString(mynumber, 36). Any ideas how to do this in SAS Base?

推荐答案

不幸的是,使用格式有很简单的方法,但是下面的数据步骤应该可以解决问题.它仅适用于正整数.

Unfortunately there is easy way to do it usings formats, but the following data step should solve the problem. It works for positive integers only.

data _null_;
 infile cards;
 input innumber;
 number = innumber;
 format base $32.;
 alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 if number = 0 then base = '0';
 else
  do while (number ne 0);
   mod = mod(number, length(alphabet));
   div = floor(number / (length(alphabet)));
   base = cats(substr(alphabet,mod+1,1),base);
   number = div;
  end;
 put innumber= base=;
cards;
0
100
2000
30000
400000
;
run;

这篇关于将数字转换为基于基数 36 的字母数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆