<?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: How to pick prime,even and odd numbers using datasteps and do loops? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410669#M100350</link>
    <description>When I exceute the code we have missing values in the dataset..array primes{50} 1; when we using 1 in this place I'm getting error...Is any thing need to change in it..&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sun, 05 Nov 2017 13:58:10 GMT</pubDate>
    <dc:creator>rajeshalwayswel</dc:creator>
    <dc:date>2017-11-05T13:58:10Z</dc:date>
    <item>
      <title>How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410643#M100341</link>
      <description>&lt;P&gt;How to pick prime,even and odd numbers using datasteps and do loops? Atleast 0 to 50?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 04:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410643#M100341</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-11-05T04:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410648#M100343</link>
      <description>&lt;P&gt;For odd/even use the mod() function.&lt;/P&gt;
&lt;P&gt;For prime numbers I'd use an array and do something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array primes{50} 1;
do i1 = 2 to 50;
  if primes{i1}
  then do;
    i2 = 2 * i1;
    do while (i2 lt 50);
      primes{i2} = 0;
      i2 + i1;
    end;
  end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that, all elements where the index is a prime number contain a 1.&lt;/P&gt;
&lt;P&gt;You can replace all 50's with a macro variable to make the code flexible.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 07:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410648#M100343</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-05T07:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410652#M100345</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2010/09/17/a-prime-number-sieve.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2010/09/17/a-prime-number-sieve.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and use MOD() to get odd or even number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 10:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410652#M100345</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-05T10:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410669#M100350</link>
      <description>When I exceute the code we have missing values in the dataset..array primes{50} 1; when we using 1 in this place I'm getting error...Is any thing need to change in it..&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 05 Nov 2017 13:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410669#M100350</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-11-05T13:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410744#M100369</link>
      <description>&lt;P&gt;A working version of the program from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;       
data _null_;
  array PRIMES{1:50} (50*1);
  do I1 = 2 to 50;              
    if PRIMES{I1} then do;
      I2 = 2 * I1;              
      do while (I2 lt 50);
        PRIMES{I2} = 0;        putlog I1= I2= PRIMES[I2]=;
        I2 + I1;
      end;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is a slightly more efficient version of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
  array PRIMES{1:50} (50*1);
  do I1 = 2 to 50;              
    do I2 = I1 to 50/I1;              
      PRIMES{I1*I2} = 0;        putlog I1= I2= PRIMES[I1*I2]=;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added the intermediate values in the log for you to see the logic.&lt;/P&gt;
&lt;P&gt;Note that Kurt's loops need to be tweaked at bit as they flag 50 as a prime.&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>Mon, 06 Nov 2017 02:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410744#M100369</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-11-06T02:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410769#M100383</link>
      <description>&lt;P&gt;my initial code was written without access to SAS from @home, therefore the "something like". It was meant to show the basic algorithm for creating Eratosthenes's sieve.&lt;/P&gt;
&lt;P&gt;A working version (syntactically and semantically, thanks to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data primes (keep=primenumber);
array primes{50} 3 _temporary_ (50*1);
do i1 = 2 to 50;
  if primes{i1}
  then do;
    i2 = 2 * i1;
    do while (i2 le 50);
      primes{i2} = 0;
      i2 + i1;
    end;
  end;
end;
do primenumber = 1 to 50;
  if primes{primenumber} then output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Nov 2017 07:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/410769#M100383</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-06T07:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick prime,even and odd numbers using datasteps and do loops?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/708582#M217779</link>
      <description>Hi Chris !!&lt;BR /&gt;can you please explain me below logic from your code ??&lt;BR /&gt;do I2 = I1 to 50/I1; &lt;BR /&gt;&lt;BR /&gt;thanks in advance !!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 29 Dec 2020 16:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-prime-even-and-odd-numbers-using-datasteps-and-do/m-p/708582#M217779</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-29T16:09:51Z</dc:date>
    </item>
  </channel>
</rss>

