<?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 SAS Macro. in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520653#M4473</link>
    <description>&lt;P&gt;A loop inside of IML terminates when IML terminates. So you can't do this looping inside of IML.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear why you are even using IML here, as you don't seem to be doing any matrix arithmetic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do this looping with a macro %DO loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if you really want to do this inside of an IML loop, you could do the sorting, correlations and data combining all using IML commands instead of PROCs and data steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Dec 2018 01:44:06 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-12-12T01:44:06Z</dc:date>
    <item>
      <title>PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520641#M4469</link>
      <description>&lt;P&gt;Hello everyone, what is wrong with the following code? I cannot get it to work.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro mymacro(mydata,X,Y,M);
proc corr data=&amp;amp;mydata outs=M;
var &amp;amp;X &amp;amp;Y;
run;

/*Now let's begin Proc IML*/
proc iml;
use &amp;amp;mydata; read all var{&amp;amp;X} into xvar;
use &amp;amp;mydata; read all var{&amp;amp;Y} into yvar;
create combined var{xvar,yvar};
append;
close combined;

use M;
read all var {&amp;amp;Y};
close M;
RR = &amp;amp;Y[4];

print RR;
AA=j(&amp;amp;M,1,0);
quit;

proc iml;
do i = 1 to &amp;amp;M;
	U=uniform(repeat(0,nrow(&amp;amp;X),1));
	create together var{&amp;amp;X,U};
	append;
	close together;
	
	proc sort data=together;
	by U;
	run;

	data together;
	merge together &amp;amp;mydata;
	run;
	
	
	proc corr data=together spearman outs=MM noprint;
	var &amp;amp;X &amp;amp;Y;
	run;
	

	use MM;
	read all var {&amp;amp;Y};
	close MM;
	R = &amp;amp;Y[4];
	*print R;
	
	if abs(R) &amp;gt; RR then AA[i]=1;
	else  AA[i]=0;
	

end;
quit;
p_value=mean(AA);
print p_value;

%mend mymacro;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 00:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520641#M4469</guid>
      <dc:creator>themanoj20080</dc:creator>
      <dc:date>2018-12-12T00:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520649#M4470</link>
      <description>&lt;P&gt;Please remember to include the portion of the SAS log that shows the erro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, the problem is that inside the (second) call to PROC IML you have a loop, but then you call PROC SORT and other procedures, which causes PROC IML to exit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc iml;
do i = 1 to &amp;amp;M;
	U=uniform(repeat(0,nrow(&amp;amp;X),1));
	create together var{&amp;amp;X,U};
	append;
	close together;
	
/**** The next statement QUITs PROC IML and starts a new procedure */
	proc sort data=together;
	by U;
	run;

	data together;
	merge together &amp;amp;mydata;
	run;	
	
	proc corr data=together spearman outs=MM noprint;
	var &amp;amp;X &amp;amp;Y;
	run;
	
/**** The next statement is invalid b/c you are no longer in PROC IML */
	use MM;
	read all var {&amp;amp;Y};
	close MM;
	R = &amp;amp;Y[4];
	*print R;
	
	if abs(R) &amp;gt; RR then AA[i]=1;
	else  AA[i]=0;
	

end;
quit;

/**** The next stmt appears to be an IML stmt, but you've already QUIT! */
p_value=mean(AA);
print p_value;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Dec 2018 01:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520649#M4470</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-12-12T01:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520651#M4471</link>
      <description>&lt;P&gt;PS. A programming tip that I often use is to completely write and debug the program before trying to wrap it into a macro.&lt;/P&gt;
&lt;P&gt;For this program, I'd use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%LET mydata,= DSName;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%LET X = XVar;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%LET Y = YVar;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%LET M = OutCorr;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and get the whole program working with those macro variables before attempting to define %MYMACRO.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 01:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520651#M4471</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-12-12T01:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520652#M4472</link>
      <description>&lt;P&gt;Thank you very much for your correction. If I quit the PROC IML after close together, will the do loop continue down to next line even after quitting PROC IML?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 01:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520652#M4472</guid>
      <dc:creator>themanoj20080</dc:creator>
      <dc:date>2018-12-12T01:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520653#M4473</link>
      <description>&lt;P&gt;A loop inside of IML terminates when IML terminates. So you can't do this looping inside of IML.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear why you are even using IML here, as you don't seem to be doing any matrix arithmetic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do this looping with a macro %DO loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if you really want to do this inside of an IML loop, you could do the sorting, correlations and data combining all using IML commands instead of PROCs and data steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 01:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520653#M4473</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-12T01:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520656#M4475</link>
      <description>&lt;P&gt;It looks like this might be some sort of simulation study of the correlation between ... something? If you tell us (in words) what you are trying to accomplish, perhaps we could&amp;nbsp;provide a way to compute it. That might be more efficient than you posting many failed attempts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 02:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520656#M4475</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-12-12T02:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520660#M4476</link>
      <description>&lt;P&gt;Yes you are right. So I have two variables X and Y coming from mydata and M is the number of simulations. I calculate the spearman correlation between X and Y at first. Then I loop over M times and resample X and compute correlation M times between resampled X and Y in each loop. Y is not resampled. Finally I find&amp;nbsp;the &amp;nbsp;proportion&amp;nbsp;of times that the correlation in each loop is greater than the original correlation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 02:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520660#M4476</guid>
      <dc:creator>themanoj20080</dc:creator>
      <dc:date>2018-12-12T02:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520749#M4477</link>
      <description>&lt;P&gt;Okay, so this is a bootstrap analysis (or maybe a permutation test) for the Spearman correlation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've recently written a &lt;A href="https://blogs.sas.com/content/iml/2018/12/12/essential-guide-bootstrapping-sas.html?preview_id=22250&amp;amp;preview_nonce=9a7d06d02f&amp;amp;_thumbnail_id=19669&amp;amp;preview=true" target="_self"&gt;Guide to Bootstrapping in SAS&lt;/A&gt;&amp;nbsp;that you might want to read. Click on the link that says "The basic bootstrap in SAS/IML" for an overview of how to use SAS/IML (although you can also&amp;nbsp;compute this analysis without IML.)&lt;/P&gt;
&lt;P&gt;The list includes a link to the article &lt;A href="https://blogs.sas.com/content/iml/2011/11/02/how-to-compute-p-values-for-a-bootstrap-distribution.html" target="_self"&gt;"How to compute a p-value for a bootstrap analysis."&lt;/A&gt;&amp;nbsp;I suggest the second formula by Davison and Hinkley (1997, p 141) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this for a class? If so, let me give you some hints rather than the complete solution:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In SAS/IML, the CORR function supports the "Spearman" option, so you can compute the statistics in IML, if you want.&lt;/LI&gt;
&lt;LI&gt;The SAMPLE function in SAS/IML supports random sampling with replacement. So if X is a vector, then &lt;FONT face="courier new,courier"&gt;bootX&amp;nbsp;= sample(X);&lt;/FONT&gt; is a bootstrap sample from X.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you do it in SAS/IML, it will take about a dozen lines, with no need to call any other SAS procedures.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 11:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520749#M4477</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-12-12T11:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML inside SAS Macro.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520761#M4478</link>
      <description>Okay. Thank you very much. You don't have to provide me complete solution. These links are helpful and I should be good now.</description>
      <pubDate>Wed, 12 Dec 2018 11:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-IML-inside-SAS-Macro/m-p/520761#M4478</guid>
      <dc:creator>themanoj20080</dc:creator>
      <dc:date>2018-12-12T11:49:45Z</dc:date>
    </item>
  </channel>
</rss>

