<?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: Should the GRAYCODE function return a row vector in IML? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182395#M1823</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand your frustration. I have blogged about the problem of calling Base SAS functions that require a list of parameters, and have provided a method that I often use to handle INPUT parameters: &lt;A href="http://blogs.sas.com/content/iml/2011/06/08/calling-base-sas-functions-from-sasiml-how-to-handle-argument-lists/" title="http://blogs.sas.com/content/iml/2011/06/08/calling-base-sas-functions-from-sasiml-how-to-handle-argument-lists/"&gt; Calling Base SAS functions from SAS/IML: How to handle argument lists? - The DO Loop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case, the Base SAS function is providing multiple OUTPUT parameters, so you can't use my trick. However, you can solve your problem by using the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67239/HTML/default/viewer.htm#n0q0yntg881ujfn114v8c3x3deut.htm"&gt;CALL GRAYCODE subroutine &lt;/A&gt;rather than the GRAYCODE function.&amp;nbsp; It's not clear from your description whether you need a numerical vector or whether a character string will suffice. In the following statements, s is a character string; if you need a numerical vector, use the &lt;A href="http://blogs.sas.com/content/iml/2013/09/03/convert-a-string-into-a-vector/"&gt;new functionality of the SUBSTR function&lt;/A&gt; to convert the string to a vector:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s='0000';&lt;/P&gt;&lt;P&gt;n=length(s);&lt;/P&gt;&lt;P&gt;k=countc(s, '0');&lt;/P&gt;&lt;P&gt;do i=2 to 2##n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call graycode(k, s, n, '01');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; x = num(substr(s, 1:n, 1));&amp;nbsp; /* necessary */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print i&amp;nbsp; k s x;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, when the initial string has 19 characters (s='0000000000000000000';) the program completes in less than a second, so it appears to be sufficiently efficient.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Jun 2014 13:37:43 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2014-06-03T13:37:43Z</dc:date>
    <item>
      <title>Should the GRAYCODE function return a row vector in IML?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182394#M1822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been experimenting with the GRAYCODE function within an IML program and thought I would post my experiences for the benefit of others.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was expecting to be able to define a vector x = j(1, 4, 0), set k = -1 and then call&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rc = graycode(k, x);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in a loop, where x would cycle through all the combinations (effectively a representation of the binary numbers 0 to 15 in a minimum change order).&amp;nbsp; If I do that, I get an unhelpful error insisting that the first argument k should be binary, I think I can see now why I get this, but not the first few times.&amp;nbsp; It seems the only way to use it, is to provide a list of scalars that have all been pre-initialised.&amp;nbsp; So the following does work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; k = -1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a = 0; b = 0; c = 0; d = 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i=1 to 2##4;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc = graycode(k, a, b, c, d);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print i k a b c d rc;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the only problem is that I am thinking of putting this in an algorithm with 2^19 iterations, and managing 19 scalars is cumbersome to say the least.&amp;nbsp; Wouldn't it make much more sense to get the scalars returned as a row vector?&amp;nbsp; My solution is to create the row vector myself using the return codes, and just feed in zeros rather than scalars. This is far from intuitive, but does do what I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; k = 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; x = j(1, 4, 0);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; rc = 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; print x rc;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i=2 to 2##4;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc = graycode(k, 0, 0, 0, 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x[rc] = 1 - x[rc];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print x rc;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried&amp;nbsp; rc = graycode(k, , , , ) but regretted it!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jun 2014 08:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182394#M1822</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2014-06-03T08:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Should the GRAYCODE function return a row vector in IML?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182395#M1823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand your frustration. I have blogged about the problem of calling Base SAS functions that require a list of parameters, and have provided a method that I often use to handle INPUT parameters: &lt;A href="http://blogs.sas.com/content/iml/2011/06/08/calling-base-sas-functions-from-sasiml-how-to-handle-argument-lists/" title="http://blogs.sas.com/content/iml/2011/06/08/calling-base-sas-functions-from-sasiml-how-to-handle-argument-lists/"&gt; Calling Base SAS functions from SAS/IML: How to handle argument lists? - The DO Loop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case, the Base SAS function is providing multiple OUTPUT parameters, so you can't use my trick. However, you can solve your problem by using the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67239/HTML/default/viewer.htm#n0q0yntg881ujfn114v8c3x3deut.htm"&gt;CALL GRAYCODE subroutine &lt;/A&gt;rather than the GRAYCODE function.&amp;nbsp; It's not clear from your description whether you need a numerical vector or whether a character string will suffice. In the following statements, s is a character string; if you need a numerical vector, use the &lt;A href="http://blogs.sas.com/content/iml/2013/09/03/convert-a-string-into-a-vector/"&gt;new functionality of the SUBSTR function&lt;/A&gt; to convert the string to a vector:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s='0000';&lt;/P&gt;&lt;P&gt;n=length(s);&lt;/P&gt;&lt;P&gt;k=countc(s, '0');&lt;/P&gt;&lt;P&gt;do i=2 to 2##n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call graycode(k, s, n, '01');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; x = num(substr(s, 1:n, 1));&amp;nbsp; /* necessary */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print i&amp;nbsp; k s x;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, when the initial string has 19 characters (s='0000000000000000000';) the program completes in less than a second, so it appears to be sufficiently efficient.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jun 2014 13:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182395#M1823</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-06-03T13:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Should the GRAYCODE function return a row vector in IML?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182396#M1824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many thanks for your tips Rick.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 08:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Should-the-GRAYCODE-function-return-a-row-vector-in-IML/m-p/182396#M1824</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2014-06-04T08:17:29Z</dc:date>
    </item>
  </channel>
</rss>

