楼主: benny10
7202 12

SAS有办法将10进位的数字转成2进位的数字吗? [推广有奖]

  • 0关注
  • 0粉丝

硕士生

4%

还不是VIP/贵宾

-

威望
0
论坛币
114 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
2230 点
帖子
99
精华
0
在线时间
67 小时
注册时间
2007-6-23
最后登录
2020-3-25

楼主
benny10 发表于 2010-1-29 20:06:53 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
SAS有办法将10进位的数字转成2进位的数字,然后再由2进位的数字转成10进位的数字吗? 那语法该怎么写呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:SAS 数字 办法 进位

回帖推荐

bobguy 发表于5楼  查看完整内容

238 data _null_; 239 x=128; 240 y=put(x, binary8.); 241 z=put(x, hex2.); 242 x2=input('111',binary8.); 243 x3=input(z,hex.); 244 put _all_; 245 run; x=128 y=10000000 z=80 x2=7 x3=128 _ERROR_=0 _N_=1 NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

本帖被以下文库推荐

沙发
crackman 发表于 2010-1-29 22:15:03
SAS格式
put X binary8.;就可以把X转变成二进制的数据
input X binary8.1;输入二进制数据,转换成十进制的

藤椅
benny10 发表于 2010-1-29 23:40:55
可否举个例子,如将210转成2进位数值的语法应如何写呢?如何将10110转成10进位呢?

板凳
醉_清风 发表于 2010-1-30 12:27:42
进来学习下
从来不需要想起 永远也不会忘记

报纸
bobguy 发表于 2010-1-30 12:38:52
benny10 发表于 2010-1-29 20:06
SAS有办法将10进位的数字转成2进位的数字,然后再由2进位的数字转成10进位的数字吗? 那语法该怎么写呢?
238   data _null_;
239     x=128;
240     y=put(x, binary8.);
241     z=put(x, hex2.);
242     x2=input('111',binary8.);
243     x3=input(z,hex.);
244     put _all_;
245  run;

x=128 y=10000000 z=80 x2=7 x3=128 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

地板
hengda 发表于 2010-1-30 13:12:28
请教sas除了转2,10,16进制,能否转其他进制,例如26进制?谢谢

7
benny10 发表于 2010-1-30 16:43:46
thank you very much!!

8
bobguy 发表于 2010-1-31 00:34:12
hengda 发表于 2010-1-30 13:12
请教sas除了转2,10,16进制,能否转其他进制,例如26进制?谢谢
One can write it oneself. It is not that difficulty.

9
benny10 发表于 2010-1-31 12:04:05
有现在有个问题,我将一个10进位的数值先转成2进位数再经过一些运算后,最后想再把运算后的二进制值转回10进位,但我却转不回去,请问要如何修改才能成功转换呢 ?(最后想将x2值转为10进位数)

285   input x ;
286      y=put(x, binary8.);
287       z=y/10000;
288       x1=round (z);
289       x2=x1-1*1000;
290      x3=input('x2',binary8.);
291
292
293       put  x= y= z=  x1= x2= x3=  ;
294
295  cards ;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      287:8
NOTE: Invalid argument to function INPUT at line 290 column 8.
x=218 y=11011010 z=1101.101 x1=1101 x2=101 x3=.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
296        218
x=218 y=11011010 z=1101.101 x1=1101 x2=101 x3=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 290:8
NOTE: The data set WORK.DATA21 has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
297  run;

10
bobguy 发表于 2010-1-31 23:41:51
benny10 发表于 2010-1-31 12:04
有现在有个问题,我将一个10进位的数值先转成2进位数再经过一些运算后,最后想再把运算后的二进制值转回10进位,但我却转不回去,请问要如何修改才能成功转换呢 ?(最后想将x2值转为10进位数)

285   input x ;
286      y=put(x, binary8.);
287       z=y/10000;
288       x1=round (z);
289       x2=x1-1*1000;
290      x3=input('x2',binary8.);
291
292
293       put  x= y= z=  x1= x2= x3=  ;
294
295  cards ;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      287:8
NOTE: Invalid argument to function INPUT at line 290 column 8.
x=218 y=11011010 z=1101.101 x1=1101 x2=101 x3=.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
296        218
x=218 y=11011010 z=1101.101 x1=1101 x2=101 x3=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 290:8
NOTE: The data set WORK.DATA21 has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
297  run;
286      y=put(x, binary8.);
287       z=y/10000;

Here y is char type.

Here is the math to convert 二进制值转回10进位
'101'b   = 2**2+ 2**0

'10111'b=2**4+2**2+2**1 + 2**0;

HTH


data _null_;
input x ;
     y=put(x, binary16.);
     n=length(y);
     z=0;
       do i = 1 to n;
       z+input(substr(y,i,1),1.)*2**(n-i);
     end;
     put  _all_   ;
cards ;
338
123
110
0
1
5
;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-10 18:52