<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>SAS on Feng Jiang</title>
    <link>https://fengjiang.me/tags/sas/</link>
    <description>Recent content in SAS on Feng Jiang</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 18 Nov 2020 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://fengjiang.me/tags/sas/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Export R Data to SAS</title>
      <link>https://fengjiang.me/posts/export-r-data-to-sas/</link>
      <pubDate>Wed, 18 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://fengjiang.me/posts/export-r-data-to-sas/</guid>
      <description>&lt;h2 id=&#34;the-problem&#34;&gt;The Problem&lt;/h2&gt;&#xA;&lt;p&gt;Importing SAS data into R is straightforward: the &lt;code&gt;haven&lt;/code&gt; package provides &lt;code&gt;read_sas()&lt;/code&gt;, which reads &lt;code&gt;*.sas7bdat&lt;/code&gt; files into an R data frame. Going the other direction is harder. In my experience, &lt;code&gt;*.sas7bdat&lt;/code&gt; files created by &lt;code&gt;haven::write_sas()&lt;/code&gt; were not reliably readable in SAS.&lt;/p&gt;&#xA;&lt;p&gt;At first, it seems that a shared data format should solve the problem. R can export CSV files, and SAS can import them. Wouldn&amp;rsquo;t that be enough?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Run a SAS Script from R</title>
      <link>https://fengjiang.me/posts/run-sas-script-in-r/</link>
      <pubDate>Mon, 16 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://fengjiang.me/posts/run-sas-script-in-r/</guid>
      <description>&lt;p&gt;Unlike SAS, which can host an R session after the right setup, R cannot host a SAS session directly.&lt;/p&gt;&#xA;&lt;p&gt;R can, however, call operating-system commands with &lt;code&gt;system()&lt;/code&gt;. SAS can also run a &lt;code&gt;.sas&lt;/code&gt; script from the command line. Connecting these two sides together, an R script can launch SAS and run a &lt;code&gt;.sas&lt;/code&gt; script file.&lt;/p&gt;&#xA;&lt;p&gt;The command-line syntax for running a SAS script is:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;C:\Program Files\SASHome\SASFoundation\9.4\sas.exe&amp;#34;&lt;/span&gt; -SYSIN &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path\to\example.sas&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In R, call that command through &lt;code&gt;system()&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Run R Code in SAS</title>
      <link>https://fengjiang.me/posts/run-r-code-in-sas/</link>
      <pubDate>Sun, 15 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://fengjiang.me/posts/run-r-code-in-sas/</guid>
      <description>&lt;p&gt;SAS can run R code inside a SAS program, but only after R support is enabled. The setup has two parts: turn on R integration in SAS, and tell SAS where R is installed.&lt;/p&gt;&#xA;&lt;h2 id=&#34;set-up-r-support-in-sas&#34;&gt;Set Up R Support in SAS&lt;/h2&gt;&#xA;&lt;p&gt;First, launch SAS with R support enabled. You can do this in either of two ways:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Add &lt;code&gt;-RLANG&lt;/code&gt; to the SAS command line.&lt;/li&gt;&#xA;&lt;li&gt;Add &lt;code&gt;-RLANG&lt;/code&gt; to the end of the SAS configuration file, &lt;code&gt;sasv9.cfg&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Second, tell SAS where to find R. You can do this in either of two ways:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
