<?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: Translate code from R to SAS in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140653#M7339</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a more recent version of the documenation: &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_r_toc.htm" title="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_r_toc.htm"&gt;SAS/IML(R) 13.1 User's Guide&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Sep 2014 17:15:29 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2014-09-11T17:15:29Z</dc:date>
    <item>
      <title>Translate code from R to SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140649#M7335</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do I translate this R code to SAS:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;library(lme4)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;sim&amp;lt;-function(m,n,b0=1,b1=-.5,b2=-1,testlow=1,testhi=10,xtest,xolftrue){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;a0hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;b0hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;b1hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;b2hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;d0hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;c0hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;c1hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;c2hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;c3hat&amp;lt;-0&lt;/P&gt;&lt;P&gt;for(i in 1:m){&lt;/P&gt;&lt;P&gt;olf&amp;lt;-runif(n,1,10)&lt;/P&gt;&lt;P&gt;olftrue&amp;lt;-as.vector(t(matrix(olf,nrow=n,ncol=10,byrow=F)))&lt;/P&gt;&lt;P&gt;test&amp;lt;-sample(testlow:testhi,n,replace=T)&lt;/P&gt;&lt;P&gt;olftest&amp;lt;-ifelse(olf&amp;lt;test,test,0)&lt;/P&gt;&lt;P&gt;olfind&amp;lt;-ifelse(olf&amp;lt;test,1,0)&lt;/P&gt;&lt;P&gt;olft&amp;lt;-matrix(0,nrow=n,ncol=10,byrow=T)&lt;/P&gt;&lt;P&gt;olft[cbind(1:n,olftest)]&amp;lt;-1&lt;/P&gt;&lt;P&gt;olft&amp;lt;-t(apply(olft,1,cumsum))&lt;/P&gt;&lt;P&gt;olft&amp;lt;-as.vector(t(matrix(olft,nrow=n*10,ncol=1,byrow=T)))&lt;/P&gt;&lt;P&gt;x&amp;lt;-rnorm(n,3,1)&lt;/P&gt;&lt;P&gt;mx&amp;lt;-matrix(x,nrow=n*10,ncol=1,byrow=T)&lt;/P&gt;&lt;P&gt;x&amp;lt;-as.vector(mx)&lt;/P&gt;&lt;P&gt;alpha&amp;lt;-rnorm(n,0,.5)&lt;/P&gt;&lt;P&gt;malpha&amp;lt;-matrix(alpha,nrow=n*10,ncol=1,byrow=T)&lt;/P&gt;&lt;P&gt;alpha&amp;lt;-as.vector(malpha)&lt;/P&gt;&lt;P&gt;eps&amp;lt;-rnorm(n*10,0,1)&lt;/P&gt;&lt;P&gt;time&amp;lt;-matrix(1:10,nrow=n*10,ncol=1,byrow=T)&lt;/P&gt;&lt;P&gt;time&amp;lt;-as.vector(time)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;time1&amp;lt;-pmin(time,olftrue)&lt;/P&gt;&lt;P&gt;time2&amp;lt;-pmax(time-olftrue,0)&lt;/P&gt;&lt;P&gt;y&amp;lt;-alpha+b0*x+b1*time1+b2*time2+eps&lt;/P&gt;&lt;P&gt;id&amp;lt;-as.vector(t(matrix(1:n,nrow=n,ncol=10,byrow=F)))&lt;/P&gt;&lt;P&gt;ot&amp;lt;-olft*time&lt;/P&gt;&lt;P&gt;try&amp;lt;-lmer(y~1+(1|id)+x+time1+time2)&lt;/P&gt;&lt;P&gt;a0hat&amp;lt;-a0hat+fixef(try)[[1]]&lt;/P&gt;&lt;P&gt;b0hat&amp;lt;-b0hat+fixef(try)[[2]]&lt;/P&gt;&lt;P&gt;b1hat&amp;lt;-b1hat+fixef(try)[[3]]&lt;/P&gt;&lt;P&gt;b2hat&amp;lt;-b2hat+fixef(try)[[4]]&lt;/P&gt;&lt;P&gt;timenew&amp;lt;-time-as.vector(t(matrix(olftest,nrow=n,ncol=10,byrow=F)))&lt;/P&gt;&lt;P&gt;olfind&amp;lt;-as.vector(t(matrix(olfind,nrow=n,ncol=10,byrow=F)))&lt;/P&gt;&lt;P&gt;try2&amp;lt;-lmer(y~1+(1|id)+x+timenew+olfind+timenew*olfind)&lt;/P&gt;&lt;P&gt;d0hat&amp;lt;-d0hat+fixef(try2)[[1]]&lt;/P&gt;&lt;P&gt;c0hat&amp;lt;-c0hat+fixef(try2)[[2]]&lt;/P&gt;&lt;P&gt;c1hat&amp;lt;-c1hat+fixef(try2)[[3]]&lt;/P&gt;&lt;P&gt;c2hat&amp;lt;-c2hat+fixef(try2)[[4]]&lt;/P&gt;&lt;P&gt;c3hat&amp;lt;-c3hat+fixef(try2)[[5]]&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 16:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140649#M7335</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2014-09-11T16:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Translate code from R to SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140650#M7336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You probably have to learn IML programming, or hire one to do it for. There are some tools out there, but I doubt none can convert all R program to SAS out of the box.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 16:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140650#M7336</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-09-11T16:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Translate code from R to SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140651#M7337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is no automated way. I doubt if any of our readers would want to spend a bunch of time doing this. You would first have to learn PROC IML and do it. There is another possibility: You can call R from within PROC IML. See the User's Guide, or check this out:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/63541/HTML/default/viewer.htm#imlug_r_sect012.htm" title="http://support.sas.com/documentation/cdl/en/imlug/63541/HTML/default/viewer.htm#imlug_r_sect012.htm"&gt;SAS/IML(R) 9.22 User's Guide&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It is easy to embed R within an IML run, get the results and use with SAS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 16:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140651#M7337</guid>
      <dc:creator>lvm</dc:creator>
      <dc:date>2014-09-11T16:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Translate code from R to SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140652#M7338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did the program editor eat some of your code? It looks like you are missing some closing brackets (the function and the for loop).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like this is a simulation of a regression model. Presumably a mixed model, since it uses the lme4 package. Part of the missing code probably estimate parameters to obtain the sampling distribution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to say how sophisticated your SAS programming skills are, and if you know SAS/IML or only the DATA step. It would also be nice if you tell us what you ultimately hope to accomplish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two chapters about simulating regression models in the book &lt;EM&gt;&lt;A href="http://support.sas.com/publishing/authors/wicklin.html"&gt;Simulating Data with SAS&lt;/A&gt;&lt;/EM&gt;, as well as many tips for efficient simulation There are also examples at this blog: &lt;A href="http://blogs.sas.com/content/iml/tag/sampling-and-simulation/" title="http://blogs.sas.com/content/iml/tag/sampling-and-simulation/"&gt;Sampling and Simulation - The DO Loop&lt;/A&gt;&amp;nbsp; Here is a blog post that is similar to your example, but it is for a logistic model: &lt;A href="http://blogs.sas.com/content/iml/2014/06/27/simulate-many-samples-from-a-logistic-regression-model/" title="http://blogs.sas.com/content/iml/2014/06/27/simulate-many-samples-from-a-logistic-regression-model/"&gt; Simulate many samples from a logistic regression model - The DO Loop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 17:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140652#M7338</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-09-11T17:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Translate code from R to SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140653#M7339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a more recent version of the documenation: &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_r_toc.htm" title="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_r_toc.htm"&gt;SAS/IML(R) 13.1 User's Guide&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 17:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Translate-code-from-R-to-SAS/m-p/140653#M7339</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-09-11T17:15:29Z</dc:date>
    </item>
  </channel>
</rss>

