<?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: MACROS and IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280075#M2874</link>
    <description>&lt;P&gt;Remember that the macro language writes SAS code. &amp;nbsp;Because you have loops and subscripts in the SAS/IML language you ALMOST NEVER need to use macro %DO loops. &amp;nbsp;You can write this in straight IML. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think there are logical problems with your code, but that is to be expected since you haven't been able to run/debug it. Rather than trying to figure out what you are trying to do, here is some code that runs that you can then debug:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use &amp;amp;cards;
read all into cards;
close &amp;amp;cards;
value = cards[ ,+];
print cards value;
do i = 1 to ncol(cards);  /* OR nrow(cards) ?? */
   if(cards[i] = 1 &amp;amp; value &amp;lt;= 11) then do;
      value = value + 10;
      print value;
   end;
end;
if(value &amp;gt; 21) then print 0;
else if(value = 21 &amp;amp; ncol(cards) = 2) then /* or nrow(cards)??? */
    print 21.5;
else print value;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One thing for you to think about: is the 'cards' variable a row vector, a column vector, or a matrix (each row of which is a hand)? If it is a matrix, then cards[i] is not going to make sense.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2016 20:32:35 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2016-06-24T20:32:35Z</dc:date>
    <item>
      <title>MACROS and IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280058#M2873</link>
      <description>&lt;P&gt;I am trying to write this macro to calculate the hand value of cards, however I keep getting the below error. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro handValue(cards=);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; proc iml;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; use &amp;amp;cards;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; read all into cards;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; value = cards[ ,+];&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %do i = 1 %to ncol(&amp;amp;cards);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %if(cards[i] = 1 &amp;amp; value &amp;lt;= 11) %then %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value = value + 10;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print value;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %if(value &amp;gt; 21) %then print 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %else %if(value = 21 &amp;amp; ncol(cards) = 2) %then print 21.5;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %else print value;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;%mend;&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;ERROR: Required operator not found in expression: nol(&amp;amp;cards)&lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;BR /&gt;ERROR: The macro HANDVALUE will stop executing.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 20:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280058#M2873</guid>
      <dc:creator>ejohnson96</dc:creator>
      <dc:date>2016-06-24T20:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: MACROS and IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280075#M2874</link>
      <description>&lt;P&gt;Remember that the macro language writes SAS code. &amp;nbsp;Because you have loops and subscripts in the SAS/IML language you ALMOST NEVER need to use macro %DO loops. &amp;nbsp;You can write this in straight IML. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think there are logical problems with your code, but that is to be expected since you haven't been able to run/debug it. Rather than trying to figure out what you are trying to do, here is some code that runs that you can then debug:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use &amp;amp;cards;
read all into cards;
close &amp;amp;cards;
value = cards[ ,+];
print cards value;
do i = 1 to ncol(cards);  /* OR nrow(cards) ?? */
   if(cards[i] = 1 &amp;amp; value &amp;lt;= 11) then do;
      value = value + 10;
      print value;
   end;
end;
if(value &amp;gt; 21) then print 0;
else if(value = 21 &amp;amp; ncol(cards) = 2) then /* or nrow(cards)??? */
    print 21.5;
else print value;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One thing for you to think about: is the 'cards' variable a row vector, a column vector, or a matrix (each row of which is a hand)? If it is a matrix, then cards[i] is not going to make sense.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 20:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280075#M2874</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-06-24T20:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: MACROS and IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280088#M2875</link>
      <description>&lt;P&gt;When I run this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;use test_cards;&lt;BR /&gt;read all into cards;&lt;BR /&gt;value = cards[,+];&lt;BR /&gt;do i = 1 to ncol(cards);&lt;BR /&gt;if(cards[i] = 1 &amp;amp; value &amp;lt;= 11) then do;&lt;BR /&gt;value = value + 10;&lt;BR /&gt;print value;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;if(value &amp;gt; 21) then print 0;&lt;BR /&gt;else if(value = 21 &amp;amp; ncol(cards) = 2) then print 21.5;&lt;BR /&gt;else print value;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the program works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I need it to be in a macro because I need to be able to put in any hand of cards and compute the value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 21:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280088#M2875</guid>
      <dc:creator>ejohnson96</dc:creator>
      <dc:date>2016-06-24T21:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: MACROS and IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280097#M2876</link>
      <description>&lt;P&gt;That's fine. Lots of people embed SAS/IML in a macro to pass in parameters such as data set names.&amp;nbsp; My point is that you don't need %DO and %IF statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro handValue(cards=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; proc iml;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; use &amp;amp;cards;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 22:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/MACROS-and-IML/m-p/280097#M2876</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-06-24T22:40:05Z</dc:date>
    </item>
  </channel>
</rss>

