<?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: Euclids Algorithm in do while loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478252#M123322</link>
    <description>&lt;P&gt;Is there a particular reason you're making your own function here, instead of using the built in GCD function?&lt;/P&gt;
&lt;H1 id="p0413szaijg3afn1x426zwmihusz" class="xis-title"&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;GCD Function&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Returns the greatest common divisor for one or more integers.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0413szaijg3afn1x426zwmihusz.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0413szaijg3afn1x426zwmihusz.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;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/167807"&gt;@alilacey0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have worked in sas for a little over a year now off and on so I would still consider myself fairly new to the language. I am trying to compute Euclids Method to find the gcd using a do while loop in sas. I have never enjoyed loops, but I did take a stab at the loop and I pasted my code below. I do know that Euclids Method goes as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1. a = b, then a (or b)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2. a&amp;gt;b, then gcd(a-b, b)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3. a&amp;lt;b, then gcd(a, b-a)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to test the code on two random values like 18 and 48 for example. I want to be able to change a and b to whatever numbers I would like. My starting code is below. Any help would be greatly appreciated. Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc iml;&lt;BR /&gt;start func(a, b); /*start function*/&lt;BR /&gt;do while(b != 0);&lt;BR /&gt;t = b;&lt;BR /&gt;b = mod(a,b);&lt;BR /&gt;a = t;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;return(?); /*? unsure what to put here*/&lt;BR /&gt;finish(func);&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jul 2018 00:50:18 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-16T00:50:18Z</dc:date>
    <item>
      <title>Euclids Algorithm in do while loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478247#M123317</link>
      <description>&lt;P&gt;I have worked in sas for a little over a year now off and on so I would still consider myself fairly new to the language. I am trying to compute Euclids Method to find the gcd using a do while loop in sas. I have never enjoyed loops, but I did take a stab at the loop and I pasted my code below. I do know that Euclids Method goes as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1. a = b, then a (or b)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2. a&amp;gt;b, then gcd(a-b, b)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3. a&amp;lt;b, then gcd(a, b-a)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to test the code on two random values like 18 and 48 for example. I want to be able to change a and b to whatever numbers I would like. My starting code is below. Any help would be greatly appreciated. Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;start func(a, b); /*start function*/&lt;BR /&gt;do while(b != 0);&lt;BR /&gt;t = b;&lt;BR /&gt;b = mod(a,b);&lt;BR /&gt;a = t;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;return(?); /*? unsure what to put here*/&lt;BR /&gt;finish(func);&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 23:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478247#M123317</guid>
      <dc:creator>alilacey0</dc:creator>
      <dc:date>2018-07-15T23:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Euclids Algorithm in do while loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478252#M123322</link>
      <description>&lt;P&gt;Is there a particular reason you're making your own function here, instead of using the built in GCD function?&lt;/P&gt;
&lt;H1 id="p0413szaijg3afn1x426zwmihusz" class="xis-title"&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;GCD Function&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Returns the greatest common divisor for one or more integers.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0413szaijg3afn1x426zwmihusz.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0413szaijg3afn1x426zwmihusz.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;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/167807"&gt;@alilacey0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have worked in sas for a little over a year now off and on so I would still consider myself fairly new to the language. I am trying to compute Euclids Method to find the gcd using a do while loop in sas. I have never enjoyed loops, but I did take a stab at the loop and I pasted my code below. I do know that Euclids Method goes as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1. a = b, then a (or b)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2. a&amp;gt;b, then gcd(a-b, b)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3. a&amp;lt;b, then gcd(a, b-a)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to test the code on two random values like 18 and 48 for example. I want to be able to change a and b to whatever numbers I would like. My starting code is below. Any help would be greatly appreciated. Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc iml;&lt;BR /&gt;start func(a, b); /*start function*/&lt;BR /&gt;do while(b != 0);&lt;BR /&gt;t = b;&lt;BR /&gt;b = mod(a,b);&lt;BR /&gt;a = t;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;return(?); /*? unsure what to put here*/&lt;BR /&gt;finish(func);&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 00:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478252#M123322</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-16T00:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Euclids Algorithm in do while loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478253#M123323</link>
      <description>&lt;P&gt;I am trying to familiarize myself with a do while loop&amp;nbsp;and I am able to check my work with the gcd function. So I would like to create my own function with the do while loop inside of a function, almost like "for practice" so I am able to expand on loops, but I am aware of the gcd function.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 01:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478253#M123323</guid>
      <dc:creator>alilacey0</dc:creator>
      <dc:date>2018-07-16T01:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Euclids Algorithm in do while loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478264#M123332</link>
      <description>&lt;P&gt;Defining the function in &lt;STRONG&gt;proc fcmp&lt;/STRONG&gt; allows you to use it almost everywhere :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.fcmp.util;
function myGcd(x, y);
a = x; b = y;
do while (b ne 0);
    t = b;
    b = mod(a, b);
    a = t;
    end;
return (a);
endsub;
run;

options cmplib=(work.fcmp);

data have;
input a b;
datalines;
4 6
1 25
0 12
7 43
10 10
2.4 10
;

data _null_;
set have;
GCD = myGcd(a, b);
check = gcd(a, b);
put (a b gcd check) (=);
run;

proc sql;
select a, b, myGcd(a, b) as GCD
from have;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jul 2018 03:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478264#M123332</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-07-16T03:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Euclids Algorithm in do while loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478340#M123366</link>
      <description>&lt;P&gt;I remembered&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;has already written a blog about GCD() for SAT Score .&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 12:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478340#M123366</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-16T12:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Euclids Algorithm in do while loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478346#M123368</link>
      <description>&lt;P&gt;Since you posted SAS/IML code, I will answer your question by using SAS/IML code.&lt;/P&gt;
&lt;P&gt;Your code has a few problems:&lt;/P&gt;
&lt;P&gt;1. In SAS, the "not equals" operators is "^=". You were using the C and Java syntax "!=".&lt;/P&gt;
&lt;P&gt;2. The return value should be a.&lt;/P&gt;
&lt;P&gt;3. In SAS/IML, arguments to a function are passed by reference. If you change an argument in a module, it changes the value that you passed in. For the GCD algorithm this will corrupt the input data, so you should copy the arguments before you begin to modify them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
start EuclidAlg(_a, _b); /*start function*/
a = _a; b = _b;
do while(b ^= 0);
   t = b;
   b = mod(a,b);
   a = t;
end;
return(a);
finish EuclidAlg;

a = 1071;
b = 462;
gcd = EuclidAlg(a, b);
print gcd " is the GCD of " a " and " b;

/* validate by using the built-in GCD function */
validate = gcd(a,b);
print validate;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jul 2018 12:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Euclids-Algorithm-in-do-while-loop/m-p/478346#M123368</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-07-16T12:39:35Z</dc:date>
    </item>
  </channel>
</rss>

