<?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: IML inside Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645430#M192936</link>
    <description>Could you paste your code using the running man icon please. It's incoherent as is.&lt;BR /&gt;Thanks</description>
    <pubDate>Tue, 05 May 2020 22:00:35 GMT</pubDate>
    <dc:creator>ghosh</dc:creator>
    <dc:date>2020-05-05T22:00:35Z</dc:date>
    <item>
      <title>IML inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645427#M192933</link>
      <description>&lt;P&gt;Hello, I'm using IML inside of a macro (found a few threads here about the topic, but nothing worked). The IML code authored by Rick Wicklin works flawlessly. I inserted this code inside of a macro, and although the macro loops, IML values are static with the first loop. Rick Wicklin addresses a very similar issue here: &lt;A href="https://blogs.sas.com/content/iml/2013/06/19/macros-and-loops.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2013/06/19/macros-and-loops.html&lt;/A&gt;. The crux of the matter seems to be that the interactive nature of IML behaves quite differently than a traditional data step. I've tried, promise, but just can't get it done. I am grateful for any suggestions. Code is below.&amp;nbsp; Thank you, Rick Francis&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OPTIONS SOURCE SOURCE2 MACROGEN MPRINT; %MACRO combination; data comb_1; set untrimmed (keep=group lag2cvrank lag2cfo_ts lagcfo_ts); if group=&amp;amp;I and lag2cvrank eq &amp;amp;J; *keep group lagcvrank gvkey; proc iml; *XY = {1 9, 2 15, 3 19, 4 20, 10 45, 12 55, 18 78, /* 7 data points used by Sen (1968) */ 12.5 30, 4.5 50}; /* 2 outliers (not considered by Sen) */ use work.untrimmed; read all var {lag2cfo_ts lagcfo_ts group lag2cvrank} into XY; close work.untrimmed; *XY = {lag2cfo_ts lagcfo_ts}; /* Theil uses all "N choose 2" combinations of slopes of segments. Assume that the first coordinates (X) are distinct */ c = allcomb(nrow(XY), 2); /* all "N choose 2" combinations of pairs */ group = XY[1,3]; lag2cvrank = XY[1,4]; Pt1 = XY[c[,1],]; /* extract first point of line segments */ Pt2 = XY[c[,2],]; /* extract second point of line segments */ slope = (Pt1[,2] - Pt2[,2]) / (Pt1[,1] - Pt2[,1]); /* Careful! Assumes x1 ^= x2 */ m = median(slope); b = median( XY[,2] - m*XY[,1] ); /* median(y-mx) */ *group=XY[c[,3],]; *lag2cvrank=XY[c[,4],]; print (b||m)[c={'Intercept' 'Slope'} L="Method=Theil Combs=All"]; print (XY); create perm1.ts_1_&amp;amp;I&amp;amp;J var {m b group lag2cvrank}; /** create data set **/ append; /** write data in vectors **/ close perm1.ts_1_&amp;amp;I&amp;amp;J ; /** close the data set **/ %MEND combination; %MACRO LOOP; %DO I=1991 %TO 1991; %DO J=0 %TO 4; %combination; %END; %END; %MEND LOOP; %LOOP; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 21:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645427#M192933</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-05-05T21:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: IML inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645430#M192936</link>
      <description>Could you paste your code using the running man icon please. It's incoherent as is.&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 05 May 2020 22:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645430#M192936</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-05-05T22:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: IML inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645441#M192942</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Sorry, used the HTML feature. SAS code below.  Thank you.  Rick&lt;BR /&gt;&lt;BR /&gt;OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;
%MACRO combination;  

data comb_1; 
	set untrimmed (keep=group lag2cvrank lag2cfo_ts lagcfo_ts);
	if group=&amp;amp;I and lag2cvrank eq &amp;amp;J;  
	*keep group lagcvrank gvkey; 
	
proc iml;
*XY = {1  9,  2 15,  3 19, 4 20, 10 45,  12 55, 18 78, /* 7 data points used by Sen (1968) */
     12.5 30,  4.5 50};                               /* 2 outliers (not considered by Sen) */
use work.untrimmed;
read all var {lag2cfo_ts lagcfo_ts group lag2cvrank} into XY;
close work.untrimmed;

*XY = {lag2cfo_ts lagcfo_ts};
/* Theil uses all "N choose 2" combinations of slopes of segments.
   Assume that the first coordinates (X) are distinct */
c = allcomb(nrow(XY), 2);        /* all "N choose 2" combinations of pairs */
group = XY[1,3];
lag2cvrank = XY[1,4];
Pt1 = XY[c[,1],];                 /* extract first point of line segments */
Pt2 = XY[c[,2],];                 /* extract second point of line segments */
slope = (Pt1[,2] - Pt2[,2]) / (Pt1[,1] - Pt2[,1]); /* Careful! Assumes x1 ^= x2 */
m = median(slope);
b = median( XY[,2] - m*XY[,1] );  /* median(y-mx) */
*group=XY[c[,3],];
*lag2cvrank=XY[c[,4],];
print (b||m)[c={'Intercept' 'Slope'} L="Method=Theil Combs=All"];
print (XY);
create perm1.ts_1_&amp;amp;I&amp;amp;J  var {m b group lag2cvrank}; /** create data set **/
append;       /** write data in vectors **/
close perm1.ts_1_&amp;amp;I&amp;amp;J ; /** close the data set **/
%MEND combination;

%MACRO LOOP; 
	%DO I=1991 %TO 1991; 
		%DO J=0 %TO 4;
			%combination; 
		%END; 
	%END;
%MEND LOOP; 

%LOOP;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 May 2020 22:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645441#M192942</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-05-05T22:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: IML inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645454#M192952</link>
      <description>&lt;P&gt;If any of the statments like&lt;/P&gt;
&lt;PRE&gt;*XY = {lag2cfo_ts lagcfo_ts};&lt;/PRE&gt;
&lt;P&gt;are supposed to be comments then you should change them to either Macro comments&lt;/P&gt;
&lt;PRE&gt;%*XY = {lag2cfo_ts lagcfo_ts};&lt;/PRE&gt;
&lt;P&gt;or block comments (careful, don't nest these)&lt;/P&gt;
&lt;PRE&gt;/*XY = {lag2cfo_ts lagcfo_ts};*/&lt;/PRE&gt;
&lt;P&gt;Or remove the statements entirely.&lt;/P&gt;
&lt;P&gt;The non-macro comment statement can still attempt to execute inside a macro with usually poor&amp;nbsp; results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 22:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645454#M192952</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-05T22:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: IML inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645471#M192964</link>
      <description>Thank you! Very good information!</description>
      <pubDate>Tue, 05 May 2020 23:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645471#M192964</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-05-05T23:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: IML inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645486#M192979</link>
      <description>&lt;P&gt;Problem solved. A simple USE statement qualified with WHERE does the trick. This eliminates the data step.&amp;nbsp; Thanks to everyone for your comments!&amp;nbsp; Rick&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 00:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IML-inside-Macro/m-p/645486#M192979</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-05-06T00:07:43Z</dc:date>
    </item>
  </channel>
</rss>

