<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639714#M190368</link>
    <description>&lt;P&gt;Revised code, made dynamic and optimized:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let max=1000000;

data primes;
array primes {&amp;amp;max.} _temporary_ (&amp;amp;max.*1);
do i = 2 to int(sqrt(&amp;amp;max.));
  if primes{i} then do j = 2 * i to &amp;amp;max. by i;
    primes{j} = 0;
  end;
end;
do number = 2 to &amp;amp;max.;
  if primes{number} then output;
end;
keep number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I used a million because before that, there was no measurable difference between with and without the sqrt function. With a million, the difference was .06 seconds to .10 seconds in favor of using the function, using UE on a MacBook Pro.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Apr 2020 12:25:58 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-14T12:25:58Z</dc:date>
    <item>
      <title>Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639660#M190335</link>
      <description>I want prime numbers from 1 to 1000&lt;BR /&gt;Please explain the logic with using mod function</description>
      <pubDate>Tue, 14 Apr 2020 08:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639660#M190335</guid>
      <dc:creator>PurushReddy</dc:creator>
      <dc:date>2020-04-14T08:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639667#M190340</link>
      <description>&lt;P&gt;What have you tried so far? The community has many many examples of code that does this already &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 08:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639667#M190340</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-14T08:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639674#M190345</link>
      <description>&lt;P&gt;You don't need the mod() function, you use the simple elimination method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data primes;
array primes {1000} _temporary_ (1000*1);
do i = 2 to 1000;
  if primes{i} then do j = 2 * i to 1000 by i;
    primes{j} = 0;
  end;
end;
do number = 2 to 1000;
  if primes{number} then output;
end;
keep number;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Apr 2020 10:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639674#M190345</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-14T10:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639683#M190351</link>
      <description>With 1 small modification:&lt;BR /&gt;&lt;BR /&gt;do number = 2 to 1000;&lt;BR /&gt;  if primes{number} then output;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;All the best&lt;BR /&gt;Bart</description>
      <pubDate>Tue, 14 Apr 2020 10:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639683#M190351</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-14T10:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639684#M190352</link>
      <description>&lt;P&gt;Done.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 10:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639684#M190352</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-14T10:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639691#M190357</link>
      <description>Kurt,&lt;BR /&gt;To make it faster, code could change it into &lt;BR /&gt;&lt;BR /&gt;do i = 2 to int(sqrt(1000));&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Apr 2020 11:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639691#M190357</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-04-14T11:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639714#M190368</link>
      <description>&lt;P&gt;Revised code, made dynamic and optimized:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let max=1000000;

data primes;
array primes {&amp;amp;max.} _temporary_ (&amp;amp;max.*1);
do i = 2 to int(sqrt(&amp;amp;max.));
  if primes{i} then do j = 2 * i to &amp;amp;max. by i;
    primes{j} = 0;
  end;
end;
do number = 2 to &amp;amp;max.;
  if primes{number} then output;
end;
keep number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I used a million because before that, there was no measurable difference between with and without the sqrt function. With a million, the difference was .06 seconds to .10 seconds in favor of using the function, using UE on a MacBook Pro.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 12:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639714#M190368</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-14T12:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639715#M190369</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you make it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array primes {&amp;amp;max.} _temporary_;
  do number = 1 to &amp;amp;max.;
    primes{number} = 1;
  end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will reduce memory by 50%.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 12:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639715#M190369</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-14T12:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Mod function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639720#M190372</link>
      <description>&lt;P&gt;There seems to be slight tradeoff (the additional do loop added another .01 seconds), but this is a valid point when &amp;amp;max is increased by several orders of magnitude.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 12:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mod-function/m-p/639720#M190372</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-14T12:41:13Z</dc:date>
    </item>
  </channel>
</rss>

