<?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: Converting large simulation into a loop, to avoid large datasets and running out of memory in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737273#M229834</link>
    <description>&lt;P&gt;I have been reading Rick Wicklin's advice, and he is all for avoiding macros, preferring if possible data steps with BY statements. So I have tried to revert to this approach.&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;</description>
    <pubDate>Tue, 27 Apr 2021 13:46:10 GMT</pubDate>
    <dc:creator>Piers</dc:creator>
    <dc:date>2021-04-27T13:46:10Z</dc:date>
    <item>
      <title>Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737031#M229722</link>
      <description>&lt;P&gt;Hello - again&lt;/P&gt;&lt;P&gt;Attached is a script where I:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) generate all conceivable covariance matrices for a regression model A = B + C + B*C&lt;/P&gt;&lt;P&gt;2) strip out any matrix that does not have a positive determinant&lt;/P&gt;&lt;P&gt;3) re-configure the data into Type = COV form to submit to PROC SIMNORM&lt;/P&gt;&lt;P&gt;4) run the regressions on the dataset created by PROC SIMNORM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for this is that I would like to know if there are parts of the covariance space which might give rise to significant (p &amp;lt; .05) interaction terms, even though the data are derived from normal distributions&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Experienced programmers will be giggling by now because they will have predicted that I am generating huge datasets, and that PROC REG runs out of memory in the attempt to sore the output as a file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I am seeking help as to how to recode this script so that the very large data sets can be avoided (ideally I would like to have 10k duplications of each of the 651 covariance matrices, and to run each rgression on 10k data points), and proc reg does not run out of memory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help&amp;nbsp; would be very gratefully received.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piers C&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 16:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737031#M229722</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-26T16:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737075#M229744</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table macro_param_list as
select distinct rep, mtx
from reg;
quit;

%macro reg_data(rep=, mtx=);

proc reg data=reg edf tableout outest=est;
where rep = &amp;amp;rep and mtx = &amp;amp;mtx;
 model a = b c b_c;
run;


data est_&amp;amp;rep_&amp;amp;mtx; 
set est;
 if _TYPE_ ^= 'PVALUE' then delete;
 if b_c &amp;lt; 0.05 then INT = 1;
  else INT = 0;
   keep mtx b_c INT;
run;

%mend;

data run_macros;
set macro_param_list;
str = catt('%reg_data(rep=', 
            rep,
            ', mtx=',
            mtx,
            ');');
*str  should contain values that look like the following;           
*%reg_data(rep=1, mtx=5);

*call execute(str);
run;

data est1;
length source sim_run $45.;
set est_: indsname=source;
sim_run = source;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Follows the principles illustrated here:&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It doesn't create the text files, I'll leave that for you to add in. You may need to test it, SAS Academics on Demand errored out due to the size (and other reasons when a smaller size was used) but I wouldn't expect major issues, just likely bugs around parenthesis or commas. I don't have further time unfortunately, but it should get you started.&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 17:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737075#M229744</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-26T17:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737167#M229781</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very many thanks for this. But as a complete newbie to these kinds of approaches, I am struggling to find what I assume is a bug.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached a modified version of my original script with only 10 replications per matrix, and only 10 datapoints per iteration of proc simnorm. It includes your code as well, but runs much more quickly as the dataset is so much smaller.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I succeed apparently in creating both the Macro_param_list and the Run_macros steps if I keep the&amp;nbsp; &amp;nbsp; &amp;nbsp; call execute(str);&amp;nbsp; &amp;nbsp; commented out. I show a short screen shot of the latter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Piers_0-1619500569512.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58715iF57C1B3E248A3973/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Piers_0-1619500569512.png" alt="Piers_0-1619500569512.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I include&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;call execute(str);&amp;nbsp; &amp;nbsp; &amp;nbsp; by uncommenting it, I get the following sets of errors. First:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="IMG1.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58716i3CA798B953E5B3B6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="IMG1.PNG" alt="IMG1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;So, somehow the rep part is problematic - or the reference to it, although it does get to the end of the list, where 6510 observations are read, which is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I get:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="IMG2.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58717iAF41090202CB174E/image-dimensions/600x390?v=v2" width="600" height="390" role="button" title="IMG2.PNG" alt="IMG2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;It is very clear that the regressions are being run, but the datasets created for each regression are empty. Also, the filenames for each data set only contain REP_1, REP_2 etc. The Filenames do not contain information about the MTX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have time to take a second look I would be very grateful. After about 3 hours or so, I just cant spot what the error is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piers&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 05:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737167#M229781</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-27T05:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737255#M229828</link>
      <description>&lt;P&gt;Or could you try SAS/IML code ?&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; might give you an hand.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 13:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737255#M229828</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-27T13:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737273#M229834</link>
      <description>&lt;P&gt;I have been reading Rick Wicklin's advice, and he is all for avoiding macros, preferring if possible data steps with BY statements. So I have tried to revert to this approach.&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;</description>
      <pubDate>Tue, 27 Apr 2021 13:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737273#M229834</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-27T13:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737293#M229842</link>
      <description>It's missing a period after a call of the &amp;amp;rep. FYI - as mentioned your code will not run on SAS UE so it was untested.&lt;BR /&gt;&lt;BR /&gt;SAS says it's looking for &amp;amp;REP_ note the underscore means it's a different macro variable. &lt;BR /&gt;Change &lt;BR /&gt;&lt;BR /&gt;data est_&amp;amp;rep_&amp;amp;mtx; &lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt; data est_&amp;amp;rep._&amp;amp;mtx.; &lt;BR /&gt;&lt;BR /&gt;Basically add periods after the macro variables.</description>
      <pubDate>Tue, 27 Apr 2021 15:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/737293#M229842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-27T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Converting large simulation into a loop, to avoid large datasets and running out of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/738103#M230185</link>
      <description>&lt;P&gt;Very many thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found that once I could access a stable disc space area, this simulation works fine using data steps and by statements only - its also quite efficient, even though generating datasets with 3,255,000,000 rows to be fed into the regression model. This only takes ~30mins&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 07:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-large-simulation-into-a-loop-to-avoid-large-datasets/m-p/738103#M230185</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-30T07:22:53Z</dc:date>
    </item>
  </channel>
</rss>

