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
;