<?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: Vectorizing SAS code (exp, log2, max) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672046#M201900</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Do over x;&lt;BR /&gt;Result = exp(a[1]+a[2]*x)&lt;BR /&gt;End;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;DO OVER is no longer supported by SAS 9.4, as far as I can see in the documentation. It may still work, but there could possibly be situations where it doesn't work properly.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jul 2020 10:44:35 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-07-24T10:44:35Z</dc:date>
    <item>
      <title>Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671880#M201820</link>
      <description>&lt;P&gt;I'm fairly new to SAS and am working with a statistician to develop a model using PROC MCMC. It's running extremely slow and I took a look at her code to see if I can help optimize it since I have experience with Stan and pyMC3. The code has quite a few do loops, e.g.,&lt;/P&gt;&lt;PRE&gt;do i = 1 to 3000;
    result[i] = exp(a[1] + a[2] * log2(x[i]));
end;&lt;/PRE&gt;&lt;P&gt;My main experience is with Stan and pyMC3. In both of those packages many functions are vectorized. That is, the function takes a vector or matrix rather than having to operate elementwise. For example, in Stan, we could replace the do loop to get the following code:&lt;/P&gt;&lt;PRE&gt;result = exp(a[1] + a[2] * log2(x));&lt;/PRE&gt;&lt;P&gt;Avoiding loops and using the vectorized form of `exp` and `log2` in Stan greatly speeds up programming. Is this also true for SAS? If so, how would one vectorize the above code? It looks like from the documentation that log2 and exp take only scalar (i.e., floating point values) and cannot work with arrays.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 16:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671880#M201820</guid>
      <dc:creator>StanPyMC3User</dc:creator>
      <dc:date>2020-07-23T16:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671883#M201821</link>
      <description>&lt;P&gt;You can vectorize these functions using PROC IML. Whether or not that helps with PROC MCMC, I don't know.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 16:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671883#M201821</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-23T16:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671885#M201823</link>
      <description>3000 variables? That's a lot of variables to be working with so I'm not surprised at all it's slow. &lt;BR /&gt;How many rows? If you want suggestions for efficiency and can post the whole code I'm sure you'll get suggestions as well.&lt;BR /&gt;&lt;BR /&gt;I don't think a do loop is the inefficiency here - SAS typically processes data line by line but not 100$ sure how it would do it within MCMC. You could also explore forcing the data into memory instead which may speed things up. &lt;BR /&gt;&lt;BR /&gt;SASfile statement&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsglobal&amp;amp;docsetTarget=n0osyhi338pfaan1plin9ioilduk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lestmtsglobal&amp;amp;docsetTarget=n0osyhi338pfaan1plin9ioilduk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2020 16:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671885#M201823</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-23T16:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671890#M201825</link>
      <description>&lt;P&gt;One question might be why there are 3000 separate variables in the first place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How long is "extremely slow" taking and how many observations and variables are in the data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 17:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/671890#M201825</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-23T17:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672019#M201883</link>
      <description>Can you try using a do over loop rather than a simple do loop?</description>
      <pubDate>Fri, 24 Jul 2020 05:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672019#M201883</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-07-24T05:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672020#M201884</link>
      <description>Do over x;&lt;BR /&gt;Result = exp(a[1]+a[2]*x)&lt;BR /&gt;End;</description>
      <pubDate>Fri, 24 Jul 2020 05:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672020#M201884</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-07-24T05:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672046#M201900</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Do over x;&lt;BR /&gt;Result = exp(a[1]+a[2]*x)&lt;BR /&gt;End;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;DO OVER is no longer supported by SAS 9.4, as far as I can see in the documentation. It may still work, but there could possibly be situations where it doesn't work properly.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 10:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672046#M201900</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-24T10:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Vectorizing SAS code (exp, log2, max)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672062#M201906</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&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>Fri, 24 Jul 2020 11:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vectorizing-SAS-code-exp-log2-max/m-p/672062#M201906</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-07-24T11:51:35Z</dc:date>
    </item>
  </channel>
</rss>

