<?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: Proc iml: ERROR: (execution) Matrix has not been set to a value. in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456905#M4147</link>
    <description>&lt;P&gt;So, if I add an else-do, the case where the expression evaluates to zero are covered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems to me both of you are right &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;, and I get a bad mark for faulty logic&amp;nbsp;&lt;img id="smileyindifferent" class="emoticon emoticon-smileyindifferent" src="https://communities.sas.com/i/smilies/16x16_smiley-indifferent.png" alt="Smiley Indifferent" title="Smiley Indifferent" /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Apr 2018 15:09:16 GMT</pubDate>
    <dc:creator>Datino</dc:creator>
    <dc:date>2018-04-24T15:09:16Z</dc:date>
    <item>
      <title>Proc iml: ERROR: (execution) Matrix has not been set to a value.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456627#M4139</link>
      <description>&lt;P&gt;So I have the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n_periods=5;

data table1;
	input start : MMDDYY10.  end : MMDDYY10. c_date : MMDDYY10.;
	format start end c_date MMDDYY10.;
	datalines;
1/1/2016 12/31/2016 12/31/2016
7/1/2016 6/30/2017 12/31/2016
7/1/2015 6/30/2016 12/31/2016
7/1/2015 6/30/2018 12/31/2016
7/1/2013 6/30/2023 12/31/2016
9/1/2010 10/31/2020 12/31/2016
7/1/2017 6/30/2018 12/31/2016
3/1/2008 2/28/2009 12/31/2016
1/1/2013 12/31/2013 12/31/2016
9/1/2011 10/31/2012 12/31/2016
;
run;

data periods (drop=_i);
  set table1;
  array per[&amp;amp;n_periods.];
  do _i = 1 to &amp;amp;n_periods.;
    per[_i] = c_date-365*_i;
  end;
run;

proc iml;
	start factor_dev(start_dt,end_dt,c_date);
    	accrued=c_date-start_dt;
    	duration=end_dt-start_dt;
			if accrued/duration&amp;gt;1 then do ;
				factor_dev=1;
			end;
			else if accrued/duration&amp;lt;0 then do;
				factor_dev=0;
			end;
			else if accrued/duration then do;
				factor_dev=accrued/duration;
			end;
			return (factor_dev);
	finish;	
		periods=j(10,3,0);
		use periods;
		read all var _all_ into periods;
		close periods;
		factor_dev_acu=j(dimension(periods)[1,1],&amp;amp;n_periods.,0);
		 print periods;
	do i=1 to dimension(periods)[1,1];
		do j=1 to &amp;amp;n_periods.;
			factor_dev_acu[i,j]=factor_dev(periods[i,1],periods[i,2],periods[i,j+2]);
		end;
	end;
print factor_dev_acu;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run it, I get the "ERROR: (execution) Matrix has not been set to a value." error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem appears to be in line 64. I can't find the reason why it's not accepting the third parameter, if I change it to&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;periods[i,3]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The program executes without errors, but I can't seem to be able to use anything other than number constants.&lt;/P&gt;&lt;P&gt;Any idea on what I'm doing wrong?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 18:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456627#M4139</guid>
      <dc:creator>Datino</dc:creator>
      <dc:date>2018-04-23T18:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc iml: ERROR: (execution) Matrix has not been set to a value.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456660#M4140</link>
      <description>&lt;P&gt;Logic error here:&lt;/P&gt;&lt;PRE class="language-sas lia-code-sample" data-lia-code-lang="sas" data-lia-code-macro="true"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; accrued&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;duration &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This executes if accrued/duration is exactly equal to one, otherwise no value is returned, hence the error you are seeing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The proper code is&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;else do;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 20:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456660#M4140</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-23T20:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc iml: ERROR: (execution) Matrix has not been set to a value.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456669#M4141</link>
      <description>&lt;P&gt;In your IF-THEN/ELSE statements., you have handled the cases where ACCRUED is nonzero, but the error is occuring when ACCRUED=0. Define a result for that situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
else if accrued/duration then do;  /* handles all nonzero in (0,1) */  				 
  factor_dev=accrued/duration;
end;
else 
   factor_dev = THE_RESULT_WHEN_accrued_IS_ZERO;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Apr 2018 19:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456669#M4141</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-04-23T19:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc iml: ERROR: (execution) Matrix has not been set to a value.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456678#M4142</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;In your IF-THEN/ELSE statements., you have handled the cases where ACCRUED is nonzero, but the error is occuring when ACCRUED=0. Define a result for that situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
else if accrued/duration then do;  /* handles all nonzero in (0,1) */  				 
  factor_dev=accrued/duration;
end;
else 
   factor_dev = THE_RESULT_WHEN_accrued_IS_ZERO;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't see a reason to use "if accrued/duration" in this IF/THEN logic flow. It just complicates things. A simple "else do;" will work here, because cases where the ratio is &amp;lt;0 and the ratio is &amp;gt;1 are previously covered.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 20:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456678#M4142</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-23T20:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc iml: ERROR: (execution) Matrix has not been set to a value.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456728#M4144</link>
      <description>&lt;P&gt;Hi Paige. No, that logic is not correct. The&amp;nbsp; OP's last ELSE IF statement evaluates to TRUE whenever the condition is nonzero, but none of the&amp;nbsp;cases cover the situation when the expression is exactly zero.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to use IML to see this. IF-THEN/ELSE statements&amp;nbsp;are the same throughout SAS, including the DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
input accrdur @@;
if accrdur&amp;gt;1 then do ;
	factor_dev=1;
end;
else if accrdur&amp;lt;0 then do;
	factor_dev=2;
end;
else if accrdur then do;  /* TRUE when nonzero */
	factor_dev=3;
end;
else                               /* handle zero */
   factor_dev=4;
datalines;
2 -2 0.5 0
;

proc print; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Apr 2018 00:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456728#M4144</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-04-24T00:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc iml: ERROR: (execution) Matrix has not been set to a value.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456905#M4147</link>
      <description>&lt;P&gt;So, if I add an else-do, the case where the expression evaluates to zero are covered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems to me both of you are right &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;, and I get a bad mark for faulty logic&amp;nbsp;&lt;img id="smileyindifferent" class="emoticon emoticon-smileyindifferent" src="https://communities.sas.com/i/smilies/16x16_smiley-indifferent.png" alt="Smiley Indifferent" title="Smiley Indifferent" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 15:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-iml-ERROR-execution-Matrix-has-not-been-set-to-a-value/m-p/456905#M4147</guid>
      <dc:creator>Datino</dc:creator>
      <dc:date>2018-04-24T15:09:16Z</dc:date>
    </item>
  </channel>
</rss>

