I want to generate 1 to 100 number and output want in binary128. format ,
i tried but getting error
my program as below
I am using EG 8.3
data test;
do i = 1 to 100;
output;
end;
format i binary128.;
run;
ERROR 29-185: Width specified for format BINARY is invalid.
I search on sashelp but it shows specified width range for binary is 8-64 but i want it in binary128. format
Any other way or can we generate user defined format of binary128. if yes then how please help me
You could make a string of 128 ones and zeros instead.
data test;
do i = 1 to 100;
length string $128 ;
string=repeat('0',75)||put(i,binary52.);
output;
end;
run;
There is no way to store a 128 bit number in a single SAS number.
SAS uses 64 bit binary floating point numbers. Which means that it has less than 64 bits available for representing the value of the number as some are reserved for the magnitude of the number. To store 128 bits as numbers would require at least 3 numbers.
What are you actually trying to do?
You are right,
Actually,
I want to find out output in binary128. format of any random number in between zero to 2**80
@Kishor_Gavade wrote:
You are right,
Actually,
I want to find out output in binary128. format of any random number in between zero to 2**80
If you want to generate a random number between 0 and 2**80 then generate two random numbers between 0 and 2**40-1 and paste them together.
1861 data test; 1862 num1=floor((2**40-1)*rand('uniform')); 1863 num2=floor((2**40-1)*rand('uniform')); 1864 put num1= comma32. / num2= comma32. / num1 binary40. num2 binary40. ; 1865 run; num1=168,350,492,671 num2=896,948,161,791 00100111001100100111100010100111111111111101000011010110010001101100110011111111 NOTE: The data set WORK.TEST has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Hello @Tom,
I would use a 64-bit random-number generator (RNG) in this case, e.g., the 64-bit Mersenne twister:
call streaminit('MT64', 27182818);
The default RNG ("MTHybrid") supports only 32 bit, which leads to non-random digits in the last eight bits after scaling with 2**40-1), mostly "11111111" as in your example.
For a uniform distribution on {0, 1, 2, ..., 2**80-1} I think the scaling factor in the definitions of num1 and num2 should be 2**40 rather than 2**40-1.
Use BINARY64 and concatenate the result to a string of 64 zeroes.
@Kurt_Bremser wrote:
Use BINARY64 and concatenate the result to a string of 64 zeroes.
Note that BINARY64 (like HEX16) will print the bits of the floating point representation of the number, instead of the integer value it actually means.
There are 52 bits of mantissa in the 64 bit floating point numbers (so you can store 53 bits of information since the most significant one bit is implied instead of actually stored).
619 data _null_; 620 do i=0 to 3, 128, 256, 512 ; 621 put i 4. @13 i binary53. / @2 i binary64. / ; 622 end; 623 run; 0 00000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 1 00000000000000000000000000000000000000000000000000001 0011111111110000000000000000000000000000000000000000000000000000 2 00000000000000000000000000000000000000000000000000010 0100000000000000000000000000000000000000000000000000000000000000 3 00000000000000000000000000000000000000000000000000011 0100000000001000000000000000000000000000000000000000000000000000 128 00000000000000000000000000000000000000000000010000000 0100000001100000000000000000000000000000000000000000000000000000 256 00000000000000000000000000000000000000000000100000000 0100000001110000000000000000000000000000000000000000000000000000 512 00000000000000000000000000000000000000000001000000000 0100000010000000000000000000000000000000000000000000000000000000
Thanks,
but it works upto only number 2**64
what if number is larger
like i want of 2**66 number output in binary128. format
You could make a string of 128 ones and zeros instead.
data test;
do i = 1 to 100;
length string $128 ;
string=repeat('0',75)||put(i,binary52.);
output;
end;
run;
Thanks,
It works, but not perfect for higher number
also can be adjusted upto 2**64 number
as you given solution
but what for higher number like 2**65 or 2**76 etc for that i think
result gona wrong
how can achieve that for example number 2**66 only one number
-------------------------------------------
data test;
i = 2**64;
length string $128 ;
string=repeat('0',63)||put(i,binary64.);
run;
--------------------------------------------
As explained before you cannot store numbers that large exactly as NUMBERS.
So what do you want to do?
What is the purpose of this long string of binary digits?
What do the values MEAN?
i have purpose and it is not meaningless.
thats the final limitation of SAS upto binary64. I readed through documentation but i want to know any other way to get it
Since you only have 53 bits in the mantissa of 8 byte real, such integers cannot be processed in SAS anyway.
Okay
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.