<?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: To make my simulation code run faster (ideally less than an hour) in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672492#M36535</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try this (but start with smaller scale, e.g. 100):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a (drop=i);
do i = 1 to 1000000;
n = i;
output;
end;
run;
data a(drop=w x y af1 af2);
set a;
do until (w&amp;lt;1);
x = 2 *rand("Uniform") - 1;
y = 2 *rand("Uniform") - 1;
w = x**2 + y**2;
end;
w = Sqrt((-2 * (Log(w))) / w);
af1 = 1 * x * w + 0;
af2 = 1 * y * w + 0;
sim_1 = af1;
/*call symputx('sim_1'||left(n),sim_1,'g');*/
run;


data source2 (keep= sim_ML_final sim_GL_final);

array sim_[1000000] _temporary_;
do until(eof);
  set a end=eof;
  sim_[n] = sim_1;
end;

call streaminit(12345); /* to make it reproducible */

do _I_ = 1 to 1000000;
  
  sum_ML_final = 0; 
  sum_GL_final = 0;

  do point = 1 to nobs;
    set source1 point = point nobs = nobs;
    do until (w_m&amp;lt;1);
    x_m = 2 *rand("Uniform") - 1;
    y_m = 2 *rand("Uniform") - 1;
    w_m= x_m**2 + y_m**2;
    end;
    w_m = Sqrt((-2 * (Log(w_m))) / w_m);
    af1_m = 1 * x_m * w_m + 0;
    af2_m = 1 * y_m * w_m + 0;
    sim_m1 = af1_m;
    sim_m2 = af2_m;


    if mod(n,2)=0 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
    end;
    else
    if mod(n,2)=1 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
    end;

    do until (w&amp;lt;1);
    x = 2 *rand("Uniform") - 1;
    y = 2 *rand("Uniform") - 1;
    w = x**2 + y**2;
    end;
    w = Sqrt((-2 * (Log(w))) / w);
    af1 = 1 * x * w + 0;
    af2 = 1 * y * w + 0;
    sim_g1 = af1;
    sim_g2 = af2;

    if mod(n,2)=0 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g1 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
    end;
    else
    if mod(n,2)=1 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g2 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
    end;

    sim_ML_final + sim_ML;
    sim_GL_final + sim_GL;
  end;

output;
end;

stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jul 2020 11:18:38 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-07-27T11:18:38Z</dc:date>
    <item>
      <title>To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672473#M36530</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently working on a project where i converted a simulation from excel file to SAS EG. I have reduced the running time from 12hours (Excel VBA) to approx. 8 hours (SAS EG). However, my goal is to have this program run successfully under 1 hour.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would like to know if this is possible?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are my codes:&lt;/P&gt;&lt;P&gt;data a (drop=i);&lt;BR /&gt;do i = 1 to 1000000;&lt;BR /&gt;n = i;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;data a(drop=w x y af1 af2);&lt;BR /&gt;set a;&lt;BR /&gt;do until (w&amp;lt;1);&lt;BR /&gt;x = 2 *rand("Uniform") - 1;&lt;BR /&gt;y = 2 *rand("Uniform") - 1;&lt;BR /&gt;w = x**2 + y**2;&lt;BR /&gt;end;&lt;BR /&gt;w = Sqrt((-2 * (Log(w))) / w);&lt;BR /&gt;af1 = 1 * x * w + 0;&lt;BR /&gt;af2 = 1 * y * w + 0;&lt;BR /&gt;sim_1 = af1;&lt;BR /&gt;call symputx('sim_1'||left(n),sim_1,'g');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro sim_2();&lt;BR /&gt;data source2 (keep= sim_ML sim_GL);&lt;BR /&gt;set source1;&lt;BR /&gt;do until (w_m&amp;lt;1);&lt;BR /&gt;x_m = 2 *rand("Uniform") - 1;&lt;BR /&gt;y_m = 2 *rand("Uniform") - 1;&lt;BR /&gt;w_m= x_m**2 + y_m**2;&lt;BR /&gt;end;&lt;BR /&gt;w_m = Sqrt((-2 * (Log(w_m))) / w_m);&lt;BR /&gt;af1_m = 1 * x_m * w_m + 0;&lt;BR /&gt;af2_m = 1 * y_m * w_m + 0;&lt;BR /&gt;sim_m1 = af1_m;&lt;BR /&gt;sim_m2 = af2_m;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if mod(n,2)=0 then do;&lt;BR /&gt;if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;if mod(n,2)=1 then do;&lt;BR /&gt;if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do until (w&amp;lt;1);&lt;BR /&gt;x = 2 *rand("Uniform") - 1;&lt;BR /&gt;y = 2 *rand("Uniform") - 1;&lt;BR /&gt;w = x**2 + y**2;&lt;BR /&gt;end;&lt;BR /&gt;w = Sqrt((-2 * (Log(w))) / w);&lt;BR /&gt;af1 = 1 * x * w + 0;&lt;BR /&gt;af2 = 1 * y * w + 0;&lt;BR /&gt;sim_g1 = af1;&lt;BR /&gt;sim_g2 = af2;&lt;/P&gt;&lt;P&gt;if mod(n,2)=0 then do;&lt;BR /&gt;if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_g1 &amp;lt; P then sim_GLs = E*L; else sim_GL = 0;&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;if mod(n,2)=1 then do;&lt;BR /&gt;if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_g2 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%macro mcarlo();&lt;BR /&gt;%do i = 1 %to 1000000;&lt;BR /&gt;%sim_2;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;i = 1 %then %do;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;create table sum_l_&amp;amp;i as select sum(sim_ML) as sum_ML, sum(sim_GL) as sum_GL, &amp;amp;i as n from source2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%else %if &amp;amp;i &amp;gt; 1 %then %do;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;create view sum_l as select sum(sim_ML) as sum_ML, sum(sim_GL) as sum_GL, &amp;amp;i as n from source2;&lt;BR /&gt;quit;&lt;BR /&gt;proc append base=sum_l_1 data=sum_l;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Deeply appreciate for any help! Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 09:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672473#M36530</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T09:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672484#M36531</link>
      <description>&lt;P&gt;what is `source1`? any example? it's size?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 10:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672484#M36531</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-27T10:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672485#M36532</link>
      <description>source1 is the source data file. The size of source1 is not a huge data, around 4000 observations and 23 variables. The simulation that takes the most time is %macro mcarlo() and %sim_2() where it simulates 1 million random numbers.</description>
      <pubDate>Mon, 27 Jul 2020 10:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672485#M36532</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T10:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672488#M36533</link>
      <description>&lt;P&gt;Could you share some example of&amp;nbsp;&lt;SPAN&gt;source1? so we could test and play with your code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;First thing I would consider to do would be moving it all into one data step loop without macro at all. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I would use an array for dataset A (it's only 16MB) to avoid generating a million macrovariables. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You could use SASFILE statement (it opens a SAS data set and allocates enough buffers to hold the entire file in memory).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Eventually I would consider running it in parallel (here is simple tutorial you may use to learn how to do it with systask: &lt;A href="http://www.mini.pw.edu.pl/~bjablons/SASpublic/Parallel-processing-in-BASE-SAS.sas" target="_blank"&gt;http://www.mini.pw.edu.pl/~bjablons/SASpublic/Parallel-processing-in-BASE-SAS.sas&lt;/A&gt;) but as I wrote first try to put it all into one data step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Btw. 1 observation - you are using rand() function but I don't see call streaminit() what makes your exercise not reproducible.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 10:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672488#M36533</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-27T10:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672491#M36534</link>
      <description>&lt;P&gt;one more thought, doing proc append million times doesn't seem to be very practical, maybe just create a milion of `sum_l_1 -- sum_l_1000000` and then combine them into 1 dataset by use SET statement option OPEN=DEFER, something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ALL;
  set sum_l_: OPEN=DEFER;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 11:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672491#M36534</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-27T11:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672492#M36535</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try this (but start with smaller scale, e.g. 100):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a (drop=i);
do i = 1 to 1000000;
n = i;
output;
end;
run;
data a(drop=w x y af1 af2);
set a;
do until (w&amp;lt;1);
x = 2 *rand("Uniform") - 1;
y = 2 *rand("Uniform") - 1;
w = x**2 + y**2;
end;
w = Sqrt((-2 * (Log(w))) / w);
af1 = 1 * x * w + 0;
af2 = 1 * y * w + 0;
sim_1 = af1;
/*call symputx('sim_1'||left(n),sim_1,'g');*/
run;


data source2 (keep= sim_ML_final sim_GL_final);

array sim_[1000000] _temporary_;
do until(eof);
  set a end=eof;
  sim_[n] = sim_1;
end;

call streaminit(12345); /* to make it reproducible */

do _I_ = 1 to 1000000;
  
  sum_ML_final = 0; 
  sum_GL_final = 0;

  do point = 1 to nobs;
    set source1 point = point nobs = nobs;
    do until (w_m&amp;lt;1);
    x_m = 2 *rand("Uniform") - 1;
    y_m = 2 *rand("Uniform") - 1;
    w_m= x_m**2 + y_m**2;
    end;
    w_m = Sqrt((-2 * (Log(w_m))) / w_m);
    af1_m = 1 * x_m * w_m + 0;
    af2_m = 1 * y_m * w_m + 0;
    sim_m1 = af1_m;
    sim_m2 = af2_m;


    if mod(n,2)=0 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
    end;
    else
    if mod(n,2)=1 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
    end;

    do until (w&amp;lt;1);
    x = 2 *rand("Uniform") - 1;
    y = 2 *rand("Uniform") - 1;
    w = x**2 + y**2;
    end;
    w = Sqrt((-2 * (Log(w))) / w);
    af1 = 1 * x * w + 0;
    af2 = 1 * y * w + 0;
    sim_g1 = af1;
    sim_g2 = af2;

    if mod(n,2)=0 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g1 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
    end;
    else
    if mod(n,2)=1 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g2 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
    end;

    sim_ML_final + sim_ML;
    sim_GL_final + sim_GL;
  end;

output;
end;

stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 11:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672492#M36535</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-27T11:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672493#M36536</link>
      <description>Just one question, in this part:&lt;BR /&gt;``` if mod(n,2)=0 then do; ```&lt;BR /&gt;is the "n" from source1?&lt;BR /&gt;&lt;BR /&gt;Bart</description>
      <pubDate>Mon, 27 Jul 2020 11:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672493#M36536</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-27T11:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672499#M36537</link>
      <description>&lt;P&gt;Maybe you need SAS/IML to vectorize your code.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 12:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672499#M36537</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-07-27T12:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672504#M36538</link>
      <description>&lt;P&gt;To improve the efficiency of your simulation, please follow the tips in&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; "Simulation in SAS: The slow way or the BY way"&lt;/A&gt;&amp;nbsp;In brief, replace the macro loop with BY-group processing.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 12:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672504#M36538</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-07-27T12:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672512#M36539</link>
      <description>&lt;P&gt;It looks like your simulation is trying to generate a random normal variate by using &lt;A href="https://en.wikipedia.org/wiki/Marsaglia_polar_method" target="_self"&gt;the polar generation method.&lt;/A&gt;&amp;nbsp;You can&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;replace all the DO UNTIL loops with a single call to the built-in RAND("Normal") function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;It also looks like you are looking at some correlated bivariate normal variables, but I can't determine what you are trying to accomplish.&lt;/SPAN&gt;&amp;nbsp;If you tell us what you want the simulation to do, there is probably a simpler (and faster) way to accomplish it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 12:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672512#M36539</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-07-27T12:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672517#M36540</link>
      <description>&lt;P&gt;Thank you, will definitely try out this. Will keep you posted.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 12:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672517#M36540</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T12:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672518#M36541</link>
      <description>&lt;P&gt;Yes, n is the total number of rows in source1&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 12:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672518#M36541</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T12:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672519#M36542</link>
      <description>&lt;P&gt;Unfortunately I do not have license for SAS IML.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 12:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672519#M36542</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T12:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672523#M36543</link>
      <description>&lt;P&gt;Yes, I am trying to generate a random normal variate by using box muller transformation method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ultimate goal of this simulation is to obtain the sum of two variables (sum_sim_ML &amp;amp; sum_sim_GL) with 1 million simulation. Let's use sum_sim_ML as the example.&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;The equation of the both variables are similar as shown below.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if mod(n,2)=0 then do;
if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
end;
else
if mod(n,2)=1 then do;
if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
end;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* where r, ho, E, L are from source1 table while sim_1, sim_m1 and sim_m2 are randon generating numbers (rng).&amp;nbsp;

Note: n is the total observation from source1 table.&amp;nbsp;*/&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each simulation (i=1 to 1,000,000), for example, when i=1, sim_1 is applied across all 4000 observations. However, sim_m1 and sim_m2 are RNG and should be different from every observations.&amp;nbsp;After obtaining the parameters of the equation, each observation will have different sim_ML. Then, I use proc sql to get the summation of sim_ML. Finally, I compile all simulation of sum_sim_ML using proc append.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this explains well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Feel free to let me know if any further clarification is needed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 13:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672523#M36543</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T13:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672526#M36544</link>
      <description>&lt;P&gt;I have considered this method but i do not want to overload the storage by creating a million datasets.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 13:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672526#M36544</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T13:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672529#M36545</link>
      <description>&lt;P&gt;1. By looking at the code, this will create 1 million of datasets, is that right? Is there any other method without create 1 million datasets and would speed up the process?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; For this code particularly, do i need to add it to my data a since there is a rand() function?&lt;/P&gt;&lt;PRE&gt;call streaminit(12345); /* to make it reproducible */&lt;/PRE&gt;&lt;P&gt;3. I have replied to the response below which explains my ultimate goal of this simulation exercise. Kindly refer to the below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your effort, Bart.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 13:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672529#M36545</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T13:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672534#M36546</link>
      <description>&lt;P&gt;An example of source1 will be something like this:&lt;/P&gt;&lt;P&gt;ID, P,E,L,r,n,ho&lt;/P&gt;&lt;P&gt;a1,0.5,10000,0.45,0.1,1,-0.3&lt;/P&gt;&lt;P&gt;a2,0.2,67795,0.55,0.6,2,0.55&lt;/P&gt;&lt;P&gt;a3,0.6,56781,0.66,-0.8,3,0.31&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID = Identity&lt;/P&gt;&lt;P&gt;P = range from 0 to 1&lt;/P&gt;&lt;P&gt;E = greater than 0&lt;/P&gt;&lt;P&gt;L = range from 0 to 1&lt;/P&gt;&lt;P&gt;r = range from -1 to 1&lt;/P&gt;&lt;P&gt;ho = range from&amp;nbsp; -5 to 5&lt;/P&gt;&lt;P&gt;n = row number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may generate the data sample based on the criteria above. My 'source1' dataset is around 4,000 observations. Hope this helps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 13:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672534#M36546</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-27T13:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672563#M36547</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@1) no there will be 1 dataset with million observations.&lt;/P&gt;
&lt;P&gt;this loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do _I_ = 1 to 1000000;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;repeats your simulations million times (i.e. it replaces the macro)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do point = 1 to nobs;
    set source1 point = point nobs = nobs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;just loops through source1 dataset (as your macro %&lt;SPAN&gt;sim_2() was doing)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;thisto lines:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sim_ML_final + sim_ML;
sim_GL_final + sim_GL;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;are just "aggregators" and replaces proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@2) yes you need the call streaminit() [in fact also in the data step which generates dataset A]. The rand()&amp;nbsp;function is random generator but if you don't set seed every time you run it you will get different results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here is test example of your code and the one proposed by me, on the example source1 dataset (with 9 elements). After running it 1000 times your approach run about&amp;nbsp;48.38 seconds and my code run about&amp;nbsp;0.055 sec.&amp;nbsp; [btw. you had extra "s" in ```&amp;nbsp;sim_GL&lt;STRONG&gt;s&lt;/STRONG&gt; = E*L; ``` in your code]. Here is the code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source1; 
infile cards dlm = ",";
input ID $ P E L r n ho;
cards;
a1,0.5,10000,0.45,0.1,1,-0.3
a2,0.2,67795,0.55,0.6,2,0.55
a3,0.6,56781,0.66,-0.8,3,0.31
a4,0.5,10000,0.45,0.1,4,-0.3
a5,0.2,67795,0.55,0.6,5,0.55
a6,0.6,56781,0.66,-0.8,6,0.31
a7,0.5,10000,0.45,0.1,7,-0.3
a8,0.2,67795,0.55,0.6,8,0.55
a9,0.6,56781,0.66,-0.8,9,0.31
;
run;

/*
ID = Identity
P = range from 0 to 1
E = greater than 0
L = range from 0 to 1
r = range from -1 to 1
ho = range from  -5 to 5
n = row number
*/

/* "MACRO" approach */
%let number_of_iterations = 1000;

%let t = %sysfunc(time());
data a (drop=i);
  do i = 1 to &amp;amp;number_of_iterations.;
    n = i;
    output;
  end;
run;
data a(drop=w x y af1 af2);
  set a;
  call streaminit(12345); /* to make it reproducible */
  do until (w&amp;lt;1);
  x = 2 *rand("Uniform") - 1;
  y = 2 *rand("Uniform") - 1;
  w = x**2 + y**2;
  end;
  w = Sqrt((-2 * (Log(w))) / w);
  af1 = 1 * x * w + 0;
  af2 = 1 * y * w + 0;
  sim_1 = af1;
  call symputx('sim_1'||left(n),sim_1,'g');
run;


options nomprint;
%macro sim_2();
data source2 (keep= sim_ML sim_GL);
set source1;

call streaminit(12345); /* to make it reproducible */

do until (w_m&amp;lt;1);
x_m = 2 *rand("Uniform") - 1;
y_m = 2 *rand("Uniform") - 1;
w_m= x_m**2 + y_m**2;
end;
w_m = Sqrt((-2 * (Log(w_m))) / w_m);
af1_m = 1 * x_m * w_m + 0;
af2_m = 1 * y_m * w_m + 0;
sim_m1 = af1_m;
sim_m2 = af2_m;


if mod(n,2)=0 then do;
if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
end;
else
if mod(n,2)=1 then do;
if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
end;

do until (w&amp;lt;1);
x = 2 *rand("Uniform") - 1;
y = 2 *rand("Uniform") - 1;
w = x**2 + y**2;
end;
w = Sqrt((-2 * (Log(w))) / w);
af1 = 1 * x * w + 0;
af2 = 1 * y * w + 0;
sim_g1 = af1;
sim_g2 = af2;

if mod(n,2)=0 then do;
if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_g1 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
end;
else
if mod(n,2)=1 then do;
if r * ho * &amp;amp;&amp;amp;sim_1&amp;amp;i + sqrt(1-(r*ho)**2)*sim_g2 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
end;
run;

%mend;

%macro mcarlo();
%do i = 1 %to &amp;amp;number_of_iterations.;
%sim_2;

%if &amp;amp;i = 1 %then %do;
proc sql noprint;
create table sum_l_&amp;amp;i as select sum(sim_ML) as sum_ML, sum(sim_GL) as sum_GL, &amp;amp;i as n from source2;
quit;

%end;
%else %if &amp;amp;i &amp;gt; 1 %then %do;
proc sql noprint;
create view sum_l as select sum(sim_ML) as sum_ML, sum(sim_GL) as sum_GL, &amp;amp;i as n from source2;
quit;
proc append base=sum_l_1 data=sum_l;
run;
%end;

%end;
%mend;

%mcarlo()

%let t = %sysevalf( %sysfunc(time()) - &amp;amp;t. );
%put Macro version &amp;amp;=t.;


/* "DATA STEP" approach */
%let number_of_iterations = 1000;

%let t = %sysfunc(time());
data a (drop=i);
  do i = 1 to &amp;amp;number_of_iterations.;
    n = i;
    output;
  end;
run;
data a(drop=w x y af1 af2);
  set a;
  call streaminit(12345); /* to make it reproducible */
  do until (w&amp;lt;1);
  x = 2 *rand("Uniform") - 1;
  y = 2 *rand("Uniform") - 1;
  w = x**2 + y**2;
  end;
  w = Sqrt((-2 * (Log(w))) / w);
  af1 = 1 * x * w + 0;
  af2 = 1 * y * w + 0;
  sim_1 = af1;
  /*call symputx('sim_1'||left(n),sim_1,'g');*/
run;

%let t = %sysfunc(time());
data sum_l_Bart (keep= sim_ML_final sim_GL_final n);

array sim_[&amp;amp;number_of_iterations.] _temporary_;
do until(eof);
  set a end=eof;
  sim_[n] = sim_1;
end;

call streaminit(12345); /* to make it reproducible */

do _I_ = 1 to &amp;amp;number_of_iterations.;
  
  sim_ML_final = 0; 
  sim_GL_final = 0;

  do point = 1 to nobs;
    set source1 point = point nobs = nobs;
    do until (w_m&amp;lt;1);
    x_m = 2 *rand("Uniform") - 1;
    y_m = 2 *rand("Uniform") - 1;
    w_m= x_m**2 + y_m**2;
    end;
    w_m = Sqrt((-2 * (Log(w_m))) / w_m);
    af1_m = 1 * x_m * w_m + 0;
    af2_m = 1 * y_m * w_m + 0;
    sim_m1 = af1_m;
    sim_m2 = af2_m;


    if mod(n,2)=0 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
    end;
    else
    if mod(n,2)=1 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
    end;

    do until (w&amp;lt;1);
    x = 2 *rand("Uniform") - 1;
    y = 2 *rand("Uniform") - 1;
    w = x**2 + y**2;
    end;
    w = Sqrt((-2 * (Log(w))) / w);
    af1 = 1 * x * w + 0;
    af2 = 1 * y * w + 0;
    sim_g1 = af1;
    sim_g2 = af2;

    if mod(n,2)=0 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g1 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
    end;
    else
    if mod(n,2)=1 then do;
    if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g2 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
    end;

    sim_ML_final + sim_ML;
    sim_GL_final + sim_GL;
  end;
  n = _I_;
output;
end;

stop;
run;

%let t = %sysevalf( %sysfunc(time()) - &amp;amp;t. );
%put Datastep with loop &amp;amp;=t.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope it help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&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, 28 Jul 2020 10:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672563#M36547</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-28T10:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672568#M36548</link>
      <description>&lt;P&gt;And here is the log for million for 4000 obs:&lt;/P&gt;
&lt;PRE&gt;1    data source0;
2    infile cards dlm = ",";
3    input ID $ P E L r n ho;
4    cards;

NOTE: The data set WORK.SOURCE0 has 10 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


15   ;
16   run;
17
18   data source1;
19     do _N_ = 1 to 400;
20       do point = 1 to nobs;
21         set source0 point = point nobs = nobs;
22         output;
23       end;
24     end;
25     stop;
26   run;

NOTE: The data set WORK.SOURCE1 has 4000 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


27
28
29   /*
30   ID = Identity
31   P = range from 0 to 1
32   E = greater than 0
33   L = range from 0 to 1
34   r = range from -1 to 1
35   ho = range from  -5 to 5
36   n = row number
37   */
38
39
40   %let number_of_iterations = 1000000;
41
42   %let t = %sysfunc(time());
43   data a (drop=i);
44     do i = 1 to &amp;amp;number_of_iterations.;
45       n = i;
46       output;
47     end;
48   run;

NOTE: The data set WORK.A has 1000000 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds


49   data a(drop=w x y af1 af2);
50     set a;
51     call streaminit(12345); /* to make it reproducible */
52     do until (w&amp;lt;1);
53     x = 2 *rand("Uniform") - 1;
54     y = 2 *rand("Uniform") - 1;
55     w = x**2 + y**2;
56     end;
57     w = Sqrt((-2 * (Log(w))) / w);
58     af1 = 1 * x * w + 0;
59     af2 = 1 * y * w + 0;
60     sim_1 = af1;
61     /*call symputx('sim_1'||left(n),sim_1,'g');*/
62   run;

NOTE: There were 1000000 observations read from the data set WORK.A.
NOTE: The data set WORK.A has 1000000 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.20 seconds
      cpu time            0.20 seconds


63
64   %let t = %sysfunc(time());
65   data sum_l_Bart (keep= sim_ML_final sim_GL_final n);
66
67   array sim_[&amp;amp;number_of_iterations.] _temporary_;
68   do until(eof);
69     set a end=eof;
70     sim_[n] = sim_1;
71   end;
72
73   call streaminit(12345); /* to make it reproducible */
74
75   do _I_ = 1 to &amp;amp;number_of_iterations.;
76
77     sum_ML_final = 0;
78     sum_GL_final = 0;
79
80     do point = 1 to nobs;
81       set source1 point = point nobs = nobs;
82       do until (w_m&amp;lt;1);
83       x_m = 2 *rand("Uniform") - 1;
84       y_m = 2 *rand("Uniform") - 1;
85       w_m= x_m**2 + y_m**2;
86       end;
87       w_m = Sqrt((-2 * (Log(w_m))) / w_m);
88       af1_m = 1 * x_m * w_m + 0;
89       af2_m = 1 * y_m * w_m + 0;
90       sim_m1 = af1_m;
91       sim_m2 = af2_m;
92
93
94       if mod(n,2)=0 then do;
95       if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m1 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
96       end;
97       else
98       if mod(n,2)=1 then do;
99       if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_m2 &amp;lt; P then sim_ML = E*L; else sim_ML = 0;
100      end;
101
102      do until (w&amp;lt;1);
103      x = 2 *rand("Uniform") - 1;
104      y = 2 *rand("Uniform") - 1;
105      w = x**2 + y**2;
106      end;
107      w = Sqrt((-2 * (Log(w))) / w);
108      af1 = 1 * x * w + 0;
109      af2 = 1 * y * w + 0;
110      sim_g1 = af1;
111      sim_g2 = af2;
112
113      if mod(n,2)=0 then do;
114      if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g1 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
115      end;
116      else
117      if mod(n,2)=1 then do;
118      if r * ho * sim_[_I_] + sqrt(1-(r*ho)**2)*sim_g2 &amp;lt; P then sim_GL = E*L; else sim_GL = 0;
119      end;
120
121      sim_ML_final + sim_ML;
122      sim_GL_final + sim_GL;
123    end;
124    n = _I_;
125  output;
126  end;
127
128  stop;
129  run;

NOTE: There were 1000000 observations read from the data set WORK.A.
NOTE: The data set WORK.SUM_L_BART has 1000000 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           39:54.36
      cpu time            39:52.71


130
131  %let t = %sysevalf( %sysfunc(time()) - &amp;amp;t. );
132  %put Datastep with loop &amp;amp;=t.;
Datastep with loop T=2394.3770000934
&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 16:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672568#M36548</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-27T16:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: To make my simulation code run faster (ideally less than an hour)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672751#M36551</link>
      <description>&lt;P&gt;Hi Bart,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tested out the code and it works fine except for one thing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output variables (sim_ML_final and sim_GL_final) increase as n increases. Can you explain the reason behind it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 08:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/To-make-my-simulation-code-run-faster-ideally-less-than-an-hour/m-p/672751#M36551</guid>
      <dc:creator>BY2</dc:creator>
      <dc:date>2020-07-28T08:27:04Z</dc:date>
    </item>
  </channel>
</rss>

