<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting a 19 length number to hex and then to a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653875#M196402</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; Inspired to look around by your clever reply, I found that someone as smart as you has &lt;A href="https://www.codeproject.com/Articles/16035/Base-Conversion-of-Very-Long-Positive-Integers" target="_self"&gt;written&lt;/A&gt; a C# script to convert extremely long positive integers from any base to any other base (bases between 2 and 36).&lt;/P&gt;
&lt;P&gt;I adapted it as a macro and it is attached below. There are probably some wrinkles remaining, but it seems to work when I tested a few numbers against the&amp;nbsp;wolfram alpha outputs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Converting from base 16 to base 10 like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%put %ConvertBase( 16, 10, 14C199723CC01C9061D2D278B5596A5EF2B9AB151539EE90FBAB0C4C8485 ) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;yields&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;143254356417698708708798794564564587087087987945645645664644646545687685&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I'll probably never use it, but here it is. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 06 Jun 2020 07:44:59 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-06-06T07:44:59Z</dc:date>
    <item>
      <title>Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653133#M196171</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to change a number like this 1105636746057493629 to hex and then back to a string that's looks like a hex e.g. 5902c33b625600 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This macro works but will only do one at a time, and I need to do thousands of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro dec2hex(dec);&lt;BR /&gt;data _null_;&lt;BR /&gt;msg=cat("&amp;amp;dec = #", put(&amp;amp;dec, hex14.));&lt;BR /&gt;put msg;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%dec2hex(&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: Arial,Helvetica,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;1105636746057493629&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I tried this to do them in bulk with this but I get results like 4.7909991E15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data add_new_column;&lt;BR /&gt;set work.Full_Report;&lt;BR /&gt;connid2 = input(Call_ID, hex14.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're not too busy could you&amp;nbsp; please give some advice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 11:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653133#M196171</guid>
      <dc:creator>sascam</dc:creator>
      <dc:date>2020-06-04T11:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653138#M196173</link>
      <description>&lt;P&gt;I assume call_id is a string (char) variable? If so, use put(call_id, $hexNN.).&lt;BR /&gt;whe NN is a number = 2x the length of call_id&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 11:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653138#M196173</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-06-04T11:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653148#M196176</link>
      <description>&lt;P&gt;Since you cannot store numbers meaningfully beyond 16 decimal digits, I assume that Call_ID is of type character.&lt;/P&gt;
&lt;P&gt;The HEX14 informat tells the INPUT function to read 14 characters as a hex value and convert it to an integer.&lt;/P&gt;
&lt;P&gt;This means that you get a completely different number, and lose information on the way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input longnum $19.;
datalines;
1105636746057493629
11056367460574aaaaa
;

data want;
set have;
longnum_read_as_hex = input(longnum,hex14.);
format longnum_read_as_hex 16.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result will be the same for both "numbers".&lt;/P&gt;
&lt;P&gt;What do you want to achieve?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 11:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653148#M196176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-04T11:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653179#M196198</link>
      <description>&lt;P&gt;Thankyou for taking the time to reply&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What am I trying to achieve?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have to two tables. One has a primary key as decimal and the other as hexdecimal. E.g.&lt;BR /&gt;1105918221034346044 and 5902C33B625600. &amp;nbsp; I need to join them on the PK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I convert the decimal so I can join it with the hexadecimal?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exponentially yours,&lt;/P&gt;&lt;P&gt;Cameron&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 12:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653179#M196198</guid>
      <dc:creator>sascam</dc:creator>
      <dc:date>2020-06-04T12:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653187#M196202</link>
      <description>&lt;P&gt;You cannot convert the decimal, as you cannot handle numbers with so many digits in SAS (reliably). You will lose precision from the 16th digit down.&lt;/P&gt;
&lt;P&gt;Converting 14 hex digits to a number will also pose problems, as 14 hex digits represent 56 bits, but the 8-byte floating point format uses only 52 bits for the mantissa. Right now I see no way how you could handle this in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;14 hex digits will result in a maximum number of&amp;nbsp;7.2058E16, which is considerably smaller than your 19-digit number, so I see no way how you could ever correlate those two.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 12:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653187#M196202</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-04T12:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653205#M196203</link>
      <description>&lt;P&gt;SAS datasets only uses two data types. Floating point numbers and fixed length character strings.&amp;nbsp; You will need to work with those fields in the source system where those data types are supported.&amp;nbsp; What is the source for this data?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 12:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653205#M196203</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-04T12:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653209#M196204</link>
      <description>The source is a DB2 database. I can use Teradata as a middleman</description>
      <pubDate>Thu, 04 Jun 2020 12:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653209#M196204</guid>
      <dc:creator>sascam</dc:creator>
      <dc:date>2020-06-04T12:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653213#M196206</link>
      <description>&lt;P&gt;I am quite sure that, within a single DBMS, the DBA will make sure that the keys have the same attributes (UUIDs nowadays). From where do you get the non-standard keys?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 13:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653213#M196206</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-04T13:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653214#M196207</link>
      <description>They aren’t from the same DBMS &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;We get one in flat file that is imported to SAS. The other is in DB2 as hexadecimal.</description>
      <pubDate>Thu, 04 Jun 2020 13:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653214#M196207</guid>
      <dc:creator>sascam</dc:creator>
      <dc:date>2020-06-04T13:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653223#M196211</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332224"&gt;@sascam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;They aren’t from the same DBMS &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;We get one in flat file that is imported to SAS. The other is in DB2 as hexadecimal.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First step is to make sure not to "import" the flat file. Instead write your own data step to "read" the file.&amp;nbsp; Then you can read that long digit string as a character variable.&amp;nbsp; Then upload that character variable into DB2 and use DB2 code to convert it to the hexadecimal format of the field you need to match.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 13:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653223#M196211</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-04T13:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653237#M196219</link>
      <description>&lt;P&gt;I still hold it that you won't be able to make a connection. A 14-digit hex code cannot contain a 19-digit decimal number. It is mathematically impossible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 14:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653237#M196219</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-04T14:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653367#M196255</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332224"&gt;@sascam&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for being late to the party. It looks like you have a (partially) mathematical problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As others have pointed out already, numeric variables in a DATA step are not suitable for 19-digit decimal integers. Luckily, &lt;EM&gt;character&lt;/EM&gt; variables (of length 19) are. With a bit of math you can convert a non-negative 19-digit decimal integer (string) into a 16-digit hexadecimal integer (string). Here's my ad-hoc solution for this (using your example numbers -- see observations no. 1 and &lt;EM&gt;5&lt;/EM&gt; -- and a few others):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dec $19.;
cards;
1105636746057493629
1105636746057493632
1105636746057490432
0024772835488574589
1105918221034346044
1234567890123456789
9999999999999999999
0000000000000000255
0000000000000000013
0000000000000000000
;

data want(drop=_h);
set have;
length hex $16 _h $10;
_h=put(input(substr(dec,8),12.),hex10.);
hex=put(input(substr(dec,1,7),7.)*5**12+input(substr(_h,1,7),hex7.),hex13.)||substr(_h,8);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs            dec                  hex

  1    1105636746057493629    0F5802C33B602C7D
  2    1105636746057493632    0F5802C33B602C80
  3    1105636746057490432    0F5802C33B602000
  4    0024772835488574589    005802C33B602C7D
  5    1105918221034346044    0F5902C33B62563C
  6    1234567890123456789    112210F47DE98115
  7    9999999999999999999    8AC7230489E7FFFF
  8    0000000000000000255    00000000000000FF
  9    0000000000000000013    000000000000000D
 10    0000000000000000000    0000000000000000&lt;/PRE&gt;
&lt;P&gt;Your macro&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;dec2hex&lt;/FONT&gt; can't do the trick, but it's interesting to see what happens: The hazardous attempt to feed the 19-digit integer&amp;nbsp;1105636746057493629 into the PUT function forces SAS to deal with an integer whose exact internal representation would require more than the available 52 mantissa bits. As a result, SAS rounds the number in the binary system (at least this happens in this example) so that the surplus least significant bits are all zero and hence can be omitted in the internal representation. I've inserted the corresponding decimal number as the new observation no. 2. As you can see, it equals the original number &lt;EM&gt;plus 3&lt;/EM&gt;&amp;nbsp;(but the difference could be larger in general). But this is, of course, still too large for the HEX14. format (as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has mentioned: the largest 14-digit hex integer has only 17, not 19 decimal digits:&amp;nbsp;72,057,594,037,927,935). In such cases SAS takes the &lt;EM&gt;last&lt;/EM&gt; 14 hex digits, in your example 5802C33B602C80. Since the leading hex digit F was cut off, the corresponding decimal number is much smaller (cf.&amp;nbsp;observation no. 4 in my example datasets after adding 3). So, the result of your macro is mathematically incorrect in &lt;EM&gt;both&lt;/EM&gt; the most significant &lt;EM&gt;and&lt;/EM&gt; the least significant hex digits.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The INPUT function in your DATA step tries to interpret the decimal number as a hexadecimal number (as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has pointed out already), which doesn't make sense.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If, for some strange reason, you really don't need the two most significant hex digits, please feel free to use &lt;FONT face="courier new,courier"&gt;substr(hex,3)&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;hex&lt;/FONT&gt;&amp;nbsp;from my code at your own risk.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My code dissects the original 19-digit integer into the first 7 and the last 12 decimal digits. The latter form an integer which SAS can safely convert into the hexadecimal system. This is done by the PUT function whose result is assigned to character variable &lt;FONT face="courier new,courier"&gt;_h&lt;/FONT&gt;. Note that 10**12-1, the largest possible 12-digit decimal integer, equals&amp;nbsp;E8D4A50FFF in the hexadecimal system, so length 10 for &lt;FONT face="courier new,courier"&gt;_h&lt;/FONT&gt; is sufficient. These 10 hex digits are then dissected as well: The last three,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;substr(_h,8)&lt;/FONT&gt;, are the last three hex digits of the final result (variable &lt;FONT face="courier new,courier"&gt;hex&lt;/FONT&gt;). The remaining first seven hex digits of &lt;FONT face="courier new,courier"&gt;_h&lt;/FONT&gt; are used in a calculation resulting in the decimal number corresponding to the first 13 hex digits of the final result. (Note that 10**12/16**3=5**12.) Since 16**13-1=2**52-1&amp;lt;2**53, there is no risk of losing precision in this calculation. Finally, this intermediate result is converted into a 13-digit hex number and concatenated with the remaining 3 hex digits mentioned earlier.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Edit:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; The underlying mathematical formula is (in SAS notation):&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;n = (k * 5**12 + m) * 16**3 + s&lt;/PRE&gt;
&lt;P&gt;where&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;n&lt;/FONT&gt; is the integer to be converted&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;r=mod(n,10**12)&lt;/FONT&gt; (only quantities derived from &lt;FONT face="courier new,courier"&gt;r&lt;/FONT&gt; are used in the formula)&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;k=(n-r)/10**12&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;s=mod(r,16**3)&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;m=(r-s)/16**3&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In your first example we have:&lt;/P&gt;
&lt;PRE&gt;n=&lt;FONT color="#3366FF"&gt;1105636&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;746057493629&lt;/FONT&gt; (hex: 0&lt;FONT color="#CC99FF"&gt;F5802C33B602&lt;/FONT&gt;&lt;FONT color="#99CC00"&gt;C7D&lt;/FONT&gt;)
r=&lt;FONT color="#FF0000"&gt;746057493629&lt;/FONT&gt;
k=&lt;FONT color="#3366FF"&gt;1105636&lt;/FONT&gt;
s=3197 (hex: &lt;FONT color="#99CC00"&gt;C7D&lt;/FONT&gt;)
m=182142942
k*5**12+m=269930846205442 (hex: &lt;FONT color="#CC99FF"&gt;F5802C33B602&lt;/FONT&gt;)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 08:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653367#M196255</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-05T08:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653462#M196297</link>
      <description>&lt;P&gt;Thank you for taking the time to fix my problem &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;, its working perfectly. That was genius.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 00:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653462#M196297</guid>
      <dc:creator>sascam</dc:creator>
      <dc:date>2020-06-05T00:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653875#M196402</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; Inspired to look around by your clever reply, I found that someone as smart as you has &lt;A href="https://www.codeproject.com/Articles/16035/Base-Conversion-of-Very-Long-Positive-Integers" target="_self"&gt;written&lt;/A&gt; a C# script to convert extremely long positive integers from any base to any other base (bases between 2 and 36).&lt;/P&gt;
&lt;P&gt;I adapted it as a macro and it is attached below. There are probably some wrinkles remaining, but it seems to work when I tested a few numbers against the&amp;nbsp;wolfram alpha outputs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Converting from base 16 to base 10 like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%put %ConvertBase( 16, 10, 14C199723CC01C9061D2D278B5596A5EF2B9AB151539EE90FBAB0C4C8485 ) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;yields&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;143254356417698708708798794564564587087087987945645645664644646545687685&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I'll probably never use it, but here it is. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 07:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653875#M196402</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-06T07:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653883#M196405</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wow, this is amazing! I'm really impressed. Just yesterday, I wrote down a note (in German) saying "&lt;EM&gt;Idea: Write a SAS program or macro or function (FCMP) ...&lt;/EM&gt;" for exactly this type of conversions (bases 2 through 36 or 37 [underscore]) "&lt;EM&gt;... ideally including non-integer numbers ... Example: c='98765', baseconv(c,10,16,6)='0181CD'&lt;/EM&gt;." I wasn't sure when I would find the time to implement this idea and also thought that someone else would have done this before. And now, only hours later, I'm being presented with a magically working macro! This is simply awe-inspiring.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for sharing this cool code!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: @Other readers of this thread: Please give likes to ChrisNZ's post. I would give more than one if I could.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 11:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653883#M196405</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-06T11:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653885#M196406</link>
      <description>Ha. Thank you for the compliment. Glad you like it. Not my algorithm though! But pretty nifty: There is no theoretical length limit except 32k. You can still work on a solution for non integers if you want, though I have trouble imagining what A.A hex is in base 10. 10+10/11? &lt;BR /&gt;Do share if you write it!  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 06 Jun 2020 11:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653885#M196406</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-06T11:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653888#M196409</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;There is no theoretical length limit except 32k.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this is particularly impressive about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;You can still work on a solution for non integers if you want, ...&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe I can focus on numbers between 0 and 1. Including the integer part for arbitrary positive numbers would just mean to prepend the result from your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;... I have trouble imagining what A.A hex is in base 10. 10+10/11? &lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;10+10/&lt;EM&gt;16&lt;/EM&gt;=10.625.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 12:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653888#M196409</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-06T12:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653889#M196410</link>
      <description>&lt;P&gt;&lt;EM&gt; &amp;gt; 10+10/16=10.625&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Ah yes of course! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 12:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653889#M196410</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-06T12:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653973#M196445</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&amp;nbsp;Here is a slightly better version, while awaiting yours. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 00:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653973#M196445</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-07T00:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a 19 length number to hex and then to a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/654626#M196566</link>
      <description>&lt;P&gt;Great, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;, thanks again, also for motivating me to write code for the fractional part (attached). I went for a PROC FCMP approach, just to try a different route.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few test cases:&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input inbase outbase outlen fp :$80.;
length cfp $100;
cfp=baseconvfp(fp,inbase,outbase,outlen);
cards;
 10  2 24 2
 10  8  8 2
 10 16  6 2
 32 16  5 TEST
 10  7 55 142857142857142857142857142857142857142857143
  8 10 22 4743357156277512370127634
 16 10 25 0123456789ABCDEFGHIJKL
111 10 30 1 
111 10 30 11111111111111
 28 36  3 M08A
;&lt;/CODE&gt;&lt;/PRE&gt;
Result:&lt;BR /&gt;&lt;LI-CODE lang="markup"&gt;Obs    inbase    outbase    outlen    fp                                               cfp

  1       10         2        24      2                                                001100110011001100110011
  2       10         8         8      2                                                14631463
  3       10        16         6      2                                                333333
  4       32        16         5      TEST                                             EBB9D
  5       10         7        55      142857142857142857142857142857142857142857143    1000000000000000000000000000000000000000000000000000004
  6        8        10        22      4743357156277512370127634                        6180339887498948482045
  7       16        10        25      0123456789ABCDEFGHIJKL                           0044444444444444444444444
  8      111        10        30      1                                                009009009009009009009009009009
  9      111        10        30      11111111111111                                   009090909090909090909090909090
 10       28        36         3      M08A                                             SAS&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;
&lt;P&gt;This version doesn't contain parameter checks. For people who know what they're doing it can even be useful to go beyond the "limits": For example,&amp;nbsp;"invalid" digits such as G, H, etc. in a hexadecimal input are reasonably interpreted as 16, 17, etc. (see 7th test case: computes 1/16² + 2/16³ + ... + 21/16²² ≈ 1/15² = 0.0044444...). Similarly, bases &amp;gt;36 are no problem (especially on the input side) as long as the digits are not too large. (Application: Compute 1/n to many decimals by converting "1", i.e. 0.1, from base n to base 10. See 8th test case for n=111.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As mentioned earlier, converting an arbitrary number &amp;gt;=0 is now as simple as concatenating two strings. Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let hex=7E4.0F91;
%let dec=%ConvertBase(16,10,%scan(&amp;amp;hex,1)).%sysfunc(baseconvfp(%scan(&amp;amp;hex,2),16,10,4));
%put &amp;amp;=dec; /* DEC=2020.0608 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm really glad to have these new tools available. They will be useful for investigating numeric representation issues among other things. Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332224"&gt;@sascam&lt;/a&gt;&amp;nbsp;for sparking this discussion.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 21:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/654626#M196566</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-08T21:30:39Z</dc:date>
    </item>
  </channel>
</rss>

