<?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: Mod function with big number in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546600#M8237</link>
    <description>&lt;P&gt;Ok thanks.&lt;/P&gt;&lt;P&gt;Are there other functions that let me to do this calculate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2019 17:10:57 GMT</pubDate>
    <dc:creator>Tiri6</dc:creator>
    <dc:date>2019-03-27T17:10:57Z</dc:date>
    <item>
      <title>Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546583#M8235</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need help with the MOD function with a big number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; asd;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; check &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;30.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;check = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;310300000604156791754311182900&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Y =mod(check,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;97&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;i can't do this data step because of this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;NOTE: Invalid argument to function MOD(3.103058E29,97) at line 2667 column 4.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;check=&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;310300000604156791754311182900&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;Y=. _ERROR_=1 _N_=1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;1 at 2667:4&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;NOTE: The data set WORK.F has 1 observations and 2 variables.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;NOTE: DATA statement used (Total process time):&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me?&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546583#M8235</guid>
      <dc:creator>Tiri6</dc:creator>
      <dc:date>2019-03-27T17:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546598#M8236</link>
      <description>&lt;P&gt;SAS uses 8 byte floating point numbers so there is no way to store that many digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546598#M8236</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-27T17:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546600#M8237</link>
      <description>&lt;P&gt;Ok thanks.&lt;/P&gt;&lt;P&gt;Are there other functions that let me to do this calculate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546600#M8237</guid>
      <dc:creator>Tiri6</dc:creator>
      <dc:date>2019-03-27T17:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546601#M8238</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197378"&gt;@Tiri6&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everybody,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i need help with the MOD function with a big number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; asd;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; check &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;30.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;check = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;310305801604100&lt;FONT color="#ff0000"&gt;571754311182900&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Y =mod(check,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;97&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;i can't do this data step because of this error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE: Invalid argument to function MOD(3.103058E29,97) at line 2667 column 4.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;check=&lt;FONT color="#ff0000"&gt;&lt;FONT color="#000000"&gt;310305801604100&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;494425342345216&lt;/FONT&gt;&lt;/STRONG&gt; Y=. _ERROR_=1 _N_=1&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;1 at 2667:4&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE: The data set WORK.F has 1 observations and 2 variables.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE: DATA statement used (Total process time):&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me?&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your "number" has exceeded the storage limits of SAS. Note that the displayed numeric value is not the same as you attempted to enter, highlighted above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note from the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-paraSimpleFirst" id="p0llm475d6beo0n1vakv2ykvvuni"&gt;&lt;FONT style="background-color: rgb(252, 222, 192);"&gt;MOD&lt;/FONT&gt; returns a missing value if the remainder cannot be computed to a precision of approximately three digits or more. In this case, SAS also writes an error message to the log.&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since numbers like your example are not actually stored correctly any calculation on them is going to be somewhat unreliable in any case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without knowing what you actually need it hard to suggest an appropriate work around.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546601#M8238</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-27T17:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546602#M8239</link>
      <description>&lt;P&gt;You could try using PROC GROOVY?&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p1x8agymll9gten1ocziihptcjzj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p1x8agymll9gten1ocziihptcjzj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.tutorialspoint.com/groovy/groovy_data_types.htm" target="_blank"&gt;https://www.tutorialspoint.com/groovy/groovy_data_types.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546602#M8239</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-27T17:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546610#M8240</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197378"&gt;@Tiri6&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has pointed out already, almost all integers of this length cannot be stored in a &lt;EM&gt;numeric&lt;/EM&gt; variable in SAS without a substantial loss of precision (which would render any MOD function value useless). Note the discrepancy between your numeric literal (ending in ...2900) and the corresponding value in the log (ending in ...5216).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, it is no problem to store this string of digits in a character variable and apply some basic mathematics to obtain the desired result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create auxiliary table containing the values m=mod(10**k, 97) for k=0, ..., 100 */

data tmp;
m=1;
do k=0 to 100;
  m=mod(m,97);
  output;
  m=10*m;
end;
run;

/* Compute y=mod(check,97) */

data asd(keep=check y);
length check $101;
check = '310305801604100571754311182900';
do i=length(check) to 1 by -1;
  set tmp;
  s+input(char(check,i),1.)*m;
end;
y=mod(s,97);
output;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, 30 instead of 101 would be a sufficient length for this particular value of CHECK (and similarly 29 instead of 100 a sufficient end value of the DO loop in the first data step). I've just chosen a larger value to allow for even longer integers (of up to 101 digits).&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546610#M8240</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-03-27T17:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546620#M8241</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; &amp;nbsp;That kinda brilliance is incredible and teasing. Why do you have to make "wannbe-reinhard's" cry? Where i have sinned? Can this be helped with a notes on &lt;STRONG&gt;&lt;EM&gt;how the math works&lt;/EM&gt;&lt;/STRONG&gt;(when you have moment plz)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546620#M8241</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T17:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546669#M8245</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can this be helped with a notes on &lt;STRONG&gt;&lt;EM&gt;how the math works&lt;/EM&gt;&lt;/STRONG&gt;(when you have moment plz)&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's no rocket science, really. &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;Mathematically, we can write the integer in question as&lt;/P&gt;
&lt;PRE&gt;3*10**29 + 1*10**28 + 0*10**27 + ... + 9*100 + 0*10 + 0*1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results from algebra (keyword: quotient ring &lt;STRONG&gt;Z&lt;/STRONG&gt;/n&lt;STRONG&gt;Z&lt;/STRONG&gt;) imply that&lt;/P&gt;
&lt;PRE&gt;(1)  mod(a+b,c)=mod(mod(a,c)+mod(b,c),c)&lt;/PRE&gt;
&lt;PRE&gt;(2)  mod(a*b,c)=mod(mod(a,c)*mod(b,c),c)&lt;/PRE&gt;
&lt;PRE&gt;(3)  mod(mod(a,c),c)=mod(a,c)&lt;/PRE&gt;
&lt;P&gt;for "all" integers a&amp;gt;=0, b&amp;gt;=0 and c&amp;gt;0. ("All" that the MOD function in SAS allows. Note also that for negative a or b the MOD function &lt;EM&gt;in SAS&lt;/EM&gt; behaves in a way that equation (1) does not hold in general.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, we can compute the desired result by the rules above as&lt;/P&gt;
&lt;PRE&gt;mod(3*mod(10**29, 97) + 1*mod(10**28, 97) + ... + 0*mod(10**0, 97), 97)&lt;/PRE&gt;
&lt;P&gt;The sum in the argument of the outer MOD function is accumulated in the DO loop of the second data step (variable S), starting from the rightmost term. The outer MOD function is called in the final assignment statement (&lt;FONT face="courier new,courier"&gt;y=...&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Side note: If there was a risk that the sum in S exceeds &lt;FONT face="courier new,courier"&gt;constant('exactint')=9.007...E15&lt;/FONT&gt;, we could apply the MOD function in each iteration of the DO loop, i.e., insert &lt;FONT face="courier new,courier"&gt;s=mod(s,97);&lt;/FONT&gt; before the END statement. But we are far away from that risk: s=3494 in the example.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously,&amp;nbsp;a lookup table for&amp;nbsp;&lt;FONT face="courier new,courier"&gt;mod(10**k, 97), k=0, 1, ..., 29,&amp;nbsp;&lt;/FONT&gt;is quite helpful for the above calculation. This lookup table (in fact an extended version of it: for k=0, ..., &lt;EM&gt;100&lt;/EM&gt;) is provided by the first data step, which also makes use of rules (2) and (3).&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 20:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546669#M8245</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-03-27T20:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function with big number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546673#M8246</link>
      <description>&lt;P&gt;Thank you so much! Cheers!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 20:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546673#M8246</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T20:13:09Z</dc:date>
    </item>
  </channel>
</rss>

