<?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 inside Macro not reading matrix in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473203#M4240</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;(0.1 to 0.9 by 0.1) worked perfectly! Thank you so much!!! Learned a lot today &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Mon, 25 Jun 2018 23:13:02 GMT</pubDate>
    <dc:creator>marianaalcos</dc:creator>
    <dc:date>2018-06-25T23:13:02Z</dc:date>
    <item>
      <title>PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472471#M4215</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My task is very simple. I'm using PROC LOGISTIC with the argument ctable and pprob. I need to use this inside a macro and vary the values of pprobs from 0.01 to 1. Outside the macro, the procedure (if I pick a value for i, say 5) works perfectly. However, inside the macro the following error is displayed:&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached code (in SAS Studio) and data. The part that does not run is the very last (the logistic_macro).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro logistic_macro; 
	%do i = 1 %to 10;
     	proc logistic data=WORK.GLMDesign outmodel=final_model noprint;
		class Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28 / param=glm;
		model VAR21(event='1')= Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28
			Col2  / link=logit technique=fisher ctable  pprob= %SYSEVALF(&amp;amp;i./10) ;
		output out=preds predprobs=individual;
		score data=testset out=TestPred_new;
		run;
		proc freq data=TestPred_new;
    	table VAR21*I_VAR21 / out=CellCounts_new noprint;
		run;
		proc iml; 
		loss= j(10, 1, 0);  /*vector to store loss for different thresholds */
		use work.CellCounts_new; 
		read all var _ALL_ into M;
		close work.CellCounts_new;
		FalsePos = M[2,2] # 5; 
		FalseNeg = M[3,2]; 
		loss[i] = FalsePos + FalseNeg;
		print loss;
     %end; 
%mend;

%logistic_macro; *runs the macro;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate&amp;nbsp;your help and comments!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 13:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472471#M4215</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-22T13:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472476#M4217</link>
      <description>&lt;P&gt;Should it be :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;loss[&amp;amp;i] = FalsePos + FalseNeg;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;since IML is currently&amp;nbsp;looking for the matrix i that does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 13:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472476#M4217</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-06-22T13:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472492#M4218</link>
      <description>&lt;P&gt;In your code, you are computing a scalar for each value of &amp;amp;i. The LOSS vector will be all zeros except for the &amp;amp;i_th element. Might as well define LOSS as a scalar, since that vector is created/destroyed between PROC IML calls and it does not persist accross&amp;nbsp;invocations.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 14:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472492#M4218</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-06-22T14:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472592#M4220</link>
      <description>Thanks Ian! I forgot to add the &amp;amp; there, although my code has other bugs!</description>
      <pubDate>Fri, 22 Jun 2018 20:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472592#M4220</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-22T20:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472595#M4221</link>
      <description>Just realized that Rick!&lt;BR /&gt;Actually my code has 2 things to be fixed: first the position of the loss vector and second I was surprised because the option pprob seems not to be doing anything, which is weird.&lt;BR /&gt;&lt;BR /&gt;Well, at least now it's not running with errors. Think I might need help to figure out why pprob is not working (apparently).&lt;BR /&gt;&lt;BR /&gt;Thanks again for your help!</description>
      <pubDate>Fri, 22 Jun 2018 20:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472595#M4221</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-22T20:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472863#M4226</link>
      <description>&lt;P&gt;Rick,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's me again haha!&lt;/P&gt;&lt;P&gt;Well,&amp;nbsp;I want to ask your help because I've tried (a lot) of different approaches to declare a vector out of the 'DO' loop and then run proc logistic and another proc IML filling that vector, but I always get the same error. Do you know how can I do that in this context?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I've tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;## Approach 1 - with proc IML ###&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro logistic_macro; 
        proc iml; 
	loss= j(10, 1, 0);  /*vector to store loss for different thresholds */
	%do i = 1 %to 10;
     	proc logistic data=WORK.GLMDesign outmodel=final_model noprint;
		class Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28 / param=glm;
		model VAR21(event='1')= Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28
			Col2  / link=logit technique=fisher ctable  pprob= %SYSEVALF(&amp;amp;i./10) ;
		output out=preds predprobs=individual;
		score data=testset out=TestPred_new;
		run;
		proc freq data=TestPred_new;
    	table VAR21*I_VAR21 / out=CellCounts_new noprint;
		run;
		proc iml; 
		use work.CellCounts_new; 
		read all var _ALL_ into M;
		close work.CellCounts_new;
		FalsePos = M[2,2] # 5; 
		FalseNeg = M[3,2]; 
		loss[&amp;amp;i] = FalsePos + FalseNeg;
		print loss;
     %end; 
%mend;

%logistic_macro; *runs the macro;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;###Approach 2 - creating an array without proc iml;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro logistic_macro; 
	%do i = 1 %to 10;
     	proc logistic data=WORK.GLMDesign outmodel=final_model noprint;
		class Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28 / param=glm;
		model VAR21(event='1')= Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28
			Col2  / link=logit technique=fisher ctable  pprob= %SYSEVALF(&amp;amp;i./10) ;
		output out=preds predprobs=individual;
		score data=testset out=TestPred_new;
		run;
		proc freq data=TestPred_new;
    	table VAR21*I_VAR21 / out=CellCounts_new noprint;
		run;
		data FalsePos FalseNeg;
		set CellCounts_new;
		keep COUNT ; 
		if _N_ =2 then output FalsePos; 
		if _N_ =3 then output FalseNeg; 
		loss = FalsePos*5 + FalseNeg;
		run;
		data loss_vec;
		set loss_vec loss;
		call symputx(cat('Loss',%SYSEVALF(&amp;amp;i)),loss);
		run;
     %end;
%mend;

data loss_vec;
    input Loss1-Loss10;
    datalines; *allows to create data as belows;
	0 0 0 0 0 0 0 0 0 0
	; *must end with isolated semicolon;
%logistic_macro; *runs the macro;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of them works (and I still need to understand why assigning different values for pprob in proc logistic is not making changes to my code, but let's treat that afterwards).&lt;/P&gt;&lt;P&gt;I'd really appreciate your help here, I've been stuck for hours =/&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 04:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472863#M4226</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-25T04:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472896#M4227</link>
      <description>&lt;P&gt;Approach #1 is not working as the first time PROC LOGISTIC is run, it terminates IML completely and the matrix 'loss' is destroyed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two possible ways I can think of that will let you mix the PROCs with IML.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1) Use a macro loop around LOGISTIC and FREQ that generates a series of output data sets called CellCounts_new1, CellCounts_new2, .. , CellCounts_new10.&amp;nbsp;&amp;nbsp; Then read this series of data sets using a loop in IML and put together the vector of losses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) Investigate the SUBMIT / ENDSUBMIT block that you use to run LOGISTIC and FREQ from within IML.&amp;nbsp; This is probably the best solution since there would be&amp;nbsp;a single IML loop which submits each block of code and reads&amp;nbsp;the output data set from PROC FREQ as you have already been doing.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 08:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472896#M4227</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-06-25T08:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472911#M4228</link>
      <description>&lt;P&gt;(3) &lt;A href="https://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way.html" target="_self"&gt;Get rid of the macro loop and use BY-group processing.&lt;/A&gt;&amp;nbsp;The BY group approach will create a single data set that contains the results for all 10&amp;nbsp;logistic models. You can then process the results by using a single call to PROC IML.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 10:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/472911#M4228</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-06-25T10:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473183#M4238</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot! I decided to follow your approach because I saw it was faster.&lt;/P&gt;&lt;P&gt;I was able to successfully create the merged dataset by a new index variable i. However, I wasn't able to use this value of i inside my proc logistic function when using the argument&amp;nbsp;pprob= %SYSEVALF(i./10).&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's returning the "ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: i/10"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried without SYSEVALF and also no success.&lt;/P&gt;&lt;P&gt;I guess it's just a simple fix, but I could not find anywhere =/&lt;/P&gt;&lt;P&gt;Here's my code now:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let N = 10;
data GLMdesign_by;
set GLMDesign;
do i = 1 to &amp;amp;N;
      output;
end;
run;
proc sort data=GLMdesign_by;  by i;  run;

/* Call PROC LOGISTIC and use BY statement to compute all models */
proc logistic data=GLMdesign_by outmodel=final_model noprint;
by i;
class Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28 / param=glm;
model VAR21(event='1')= Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28
Col2  / link=logit technique=fisher ctable  pprob= %SYSEVALF(i./10) ;
output out=preds predprobs=individual;
score data=testset out=TestPred_new;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jun 2018 21:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473183#M4238</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-25T21:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473199#M4239</link>
      <description>&lt;P&gt;I'm not sure what you are trying to accomplish, but in your syntax 'i' is the name of a variable. The PPROBS= option requires a value.such as PPROB=(0.1 to 0.9 by 0.1).&lt;/P&gt;
&lt;P&gt;There is no support to have the cutpoints be&amp;nbsp;data-dependent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the cutpoints to depend on the value of the BY group, all tables and output data sets contain the BY-group variable, so you can readily use that value to process the output.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 23:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473199#M4239</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-06-25T23:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside Macro not reading matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473203#M4240</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;(0.1 to 0.9 by 0.1) worked perfectly! Thank you so much!!! Learned a lot today &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 25 Jun 2018 23:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-Macro-not-reading-matrix/m-p/473203#M4240</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-25T23:13:02Z</dc:date>
    </item>
  </channel>
</rss>

