<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>qol Blog</title>
<link>https://your-website-url.example.com/</link>
<atom:link href="https://your-website-url.example.com/index.xml" rel="self" type="application/rss+xml"/>
<description>A blog for the package qol</description>
<generator>quarto-1.8.25</generator>
<lastBuildDate>Tue, 31 Mar 2026 22:00:00 GMT</lastBuildDate>
<item>
  <title>qol 1.4: Introducing Revolutionary New Reverse Pipe Operator</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/07. Update 1.4/</link>
  <description><![CDATA[ 






<p>qol is an all purpose package which wants to make descriptive evaluations easier. It offers a lot of data wrangling and tabulation functions to generate bigger and more complex tables in less time with less code. One of the main goals is to make code more readable and have a more natural workflow. This new update therefor asked the question: Doesn’t it bother you that you normally think about the result first, but have to tediously go from A to Z to reach the goal?</p>
<p>But before I present the solution to this question, you can now chat with the qol repository - if you like - to dynamically explore what the package has to offer: <a href="https://deepwiki.com/s3rdia/qol" class="uri">https://deepwiki.com/s3rdia/qol</a></p>
<p>So what is the answer to the stated question? The new “reverse pipe operator”:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># What once was written like this</span></span>
<span id="cb1-2">result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(income <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows    =</span> age,</span>
<span id="cb1-5">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> sex,</span>
<span id="cb1-6">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values  =</span> income,</span>
<span id="cb1-7">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Can now be written like this</span></span>
<span id="cb1-10">result <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows    =</span> age,</span>
<span id="cb1-11">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> sex,</span>
<span id="cb1-12">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values  =</span> income,</span>
<span id="cb1-13">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>)</span>
<span id="cb1-14">       <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(income <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb1-15">       <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">|</span> my_data</span></code></pre></div></div>
</div>
<p>So you basically first describe what you want and then reverse engineer from there to the origin. Instead of passing data down the chain, you now pass concepts up. This makes code execution faster and saves memory, because the data always stays in its original form.</p>
<p>To further enhance the idea of making workflows faster, qol now also implements the so called “productivity_mode”. If activated, you dynamically receive information about the current pructivity state:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_productivity_mode</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-2"></span>
<span id="cb2-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Which outputs dynamically based on the current state</span></span>
<span id="cb2-4">CPU usage<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>%</span>
<span id="cb2-5">Memory<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.0</span> GB</span>
<span id="cb2-6">Developer stress<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> HIGH</span>
<span id="cb2-7">Coffee level<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> LOW</span>
<span id="cb2-8">Recommendation<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Simplify pipeline</span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Can also detect edge cases</span></span>
<span id="cb2-11">WARNING<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Productivity low.</span>
<span id="cb2-12">Recommendation<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Take a break.</span>
<span id="cb2-13"></span>
<span id="cb2-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># And of course boost performance</span></span>
<span id="cb2-15">Coffee detected. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> Increasing performance.</span></code></pre></div></div>
</div>
<p>If you want to know what else this package has to offer, you can have a look at the GitHub repository: <a href="https://github.com/s3rdia/qol" class="uri">https://github.com/s3rdia/qol</a><br>
Or the GitHub page for a full reference of the over 100 functions: <a href="https://s3rdia.github.io/qol/" class="uri">https://s3rdia.github.io/qol/</a></p>



 ]]></description>
  <category>R</category>
  <category>Update</category>
  <guid>https://your-website-url.example.com/posts/07. Update 1.4/</guid>
  <pubDate>Tue, 31 Mar 2026 22:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/07. Update 1.4/logo.png" medium="image" type="image/png" height="111" width="144"/>
</item>
<item>
  <title>qol 1.2.2: New Update Offers New Options To Compute Percentages</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/06. Update 1.2.2/</link>
  <description><![CDATA[ 






<p>The new update offers some new ways of computing different percentages. The full release notes can be seen <a href="https://github.com/s3rdia/qol/releases/tag/v1.2.2">here</a>.</p>
<p>First of all lets look at an example of how tabulation looks like. First we generate a dummy data frame an prepare our formats, which basically translate single expressions into resulting categories, which later appear in the final table.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100000</span>)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create format containers</span></span>
<span id="cb1-4">age. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb1-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb1-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb1-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb1-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb1-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb1-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">sex. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb1-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb1-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb1-15">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-16"></span>
<span id="cb1-17">education. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb1-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>            <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>),</span>
<span id="cb1-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low education"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>,</span>
<span id="cb1-20">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle education"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>,</span>
<span id="cb1-21">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high education"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)</span></code></pre></div></div>
</div>
<p>And after that we just tabulate our data without any other step in between:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define style</span></span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">column_widths =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>))</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define titles and footnotes. If you want to add hyperlinks you can do so by</span></span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># adding "link:" followed by the hyperlink to the main text.</span></span>
<span id="cb2-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_titles</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is title number 1 link: https://cran.r-project.org/"</span>,</span>
<span id="cb2-7">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is title number 2"</span>,</span>
<span id="cb2-8">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is title number 3"</span>)</span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_footnotes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is footnote number 1"</span>,</span>
<span id="cb2-11">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is footnote number 2"</span>,</span>
<span id="cb2-12">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is footnote number 3 link: https://cran.r-project.org/"</span>)</span>
<span id="cb2-13"></span>
<span id="cb2-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Output complex tables with different percentages</span></span>
<span id="cb2-15">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>),</span>
<span id="cb2-16">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education + year"</span>),</span>
<span id="cb2-17">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb2-18">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>),</span>
<span id="cb2-19">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_group  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>),</span>
<span id="cb2-20">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.,</span>
<span id="cb2-21">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.),</span>
<span id="cb2-22">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-23"></span>
<span id="cb2-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reset_style_options</span>()</span>
<span id="cb2-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reset_qol_options</span>()</span></code></pre></div></div>
</div>
<p>The update now introduces two new keywords: row_pct and col_pct. Using these in the pct_group parameter enables us to compute row and column percentages regardless of which and how many variables are used.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education"</span>),</span>
<span id="cb3-2">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,</span>
<span id="cb3-3">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb3-4">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by         =</span> state,</span>
<span id="cb3-5">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"freq"</span>),</span>
<span id="cb3-6">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_group  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"row_pct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"col_pct"</span>),</span>
<span id="cb3-7">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state =</span> state.,</span>
<span id="cb3-8">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.),</span>
<span id="cb3-9">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<p>Also new is that you can compute percentages based on an expression of a result category. For this you can use the pct_value parameter put in the variable and desired expression which is your 100% and you are good to go:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows        =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education"</span>),</span>
<span id="cb4-2">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year + sex"</span>,</span>
<span id="cb4-3">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values      =</span> weight,</span>
<span id="cb4-4">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_value   =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>),</span>
<span id="cb4-5">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.,</span>
<span id="cb4-6">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.),</span>
<span id="cb4-7">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_labels  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,</span>
<span id="cb4-8">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),</span>
<span id="cb4-9">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat_labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sum =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1000"</span>,</span>
<span id="cb4-10">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">freq =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>),</span>
<span id="cb4-11">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">box         =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Attribute"</span>,</span>
<span id="cb4-12">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm       =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<p>Here is an impression of what the results look like:</p>
<p><img src="https://your-website-url.example.com/posts/06. Update 1.2.2/results.gif" class="img-fluid"></p>
<p>You probably noticed that there are some other options which let you design your tables in a flexible way. To get a better and more in depths overview of what else this package has to offer you can have a look here: <a href="https://s3rdia.github.io/qol/" class="uri">https://s3rdia.github.io/qol/</a></p>



 ]]></description>
  <category>R</category>
  <category>Update</category>
  <guid>https://your-website-url.example.com/posts/06. Update 1.2.2/</guid>
  <pubDate>Tue, 10 Mar 2026 23:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/06. Update 1.2.2/logo.png" medium="image" type="image/png" height="70" width="144"/>
</item>
<item>
  <title>qol 1.2.1: Update Brings More Functions, More Functionalities, More Optimizations And A Bunch Of Fixes</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/05. Update 1.2.1/</link>
  <description><![CDATA[ 






<p>Another update found its way to CRAN. Thematically it goes with the previous update, meaning more on data wrangling, adjusted and added functionalities to established functions, bug fixes and optimizations.</p>
<ul>
<li>14 new functions, among other things CSV and XLSX import and export for multiple files, string manipulation, memory management and SAS Macor variables.</li>
<li>New functionalities for already established functions, like outputting all possible group variable categories, even if there are no observations for a combination or printing sub headers in tables.</li>
<li>Further optimizations to reduce memory usage and make the code run faster.</li>
<li>And of course some bug fixes.</li>
</ul>
<p>The full release notes can be seen <a href="https://github.com/s3rdia/qol/releases/tag/v1.2.1">here</a>.</p>
<section id="retrieve-a-substring" class="level1">
<h1>Retrieve A Substring</h1>
<p><a href="https://s3rdia.github.io/qol/reference/sub_string.html">sub_string</a> can extract parts of a character from the left side, right side or from the middle. It is also able to start or end at specific letter sequences instead of positions.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb1-2">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract text from the left</span></span>
<span id="cb1-5">my_data[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub_string</span>(education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract text from the right</span></span>
<span id="cb1-8">my_data[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub_string</span>(education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract text from the middle</span></span>
<span id="cb1-11">my_data[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub_string</span>(education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-12"></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Find text and extract from the left</span></span>
<span id="cb1-14">my_data[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left2"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub_string</span>(education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l"</span>)</span>
<span id="cb1-15"></span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Find text and extract from the right</span></span>
<span id="cb1-17">my_data[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right2"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub_string</span>(education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l"</span>)</span>
<span id="cb1-18"></span>
<span id="cb1-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Find text and extract from the middle</span></span>
<span id="cb1-20">my_data[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle2"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub_string</span>(education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"i"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l"</span>)</span></code></pre></div></div>
</div>
</section>
<section id="resolve-macro-variables-in-a-text" class="level1">
<h1>Resolve Macro Variables In A Text</h1>
<p><a href="https://s3rdia.github.io/qol/reference/macro.html">Macro</a> variables in ‘SAS’ can be set up with %Let and can act as global accessible variables. This in itself is nothing special to ‘R’ because basically every object created outside a function is a global variable.</p>
<p>To use these global objects within a text one has to use e.g.&nbsp;paste0(“The current year is:”, year). With the macro function one can write it like this: macro(“The current year is &amp;year”).</p>
<p>So where is the benefit? If implemented within a function, a parameter like “title” or “footnote” in the tabulation functions, can resolve these variables without the need of another function. You can just pass the character expression “The current year is &amp;year” and the implementation inside the function resolves the macro variable directly in place.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Resolving macro variable in single character</span></span>
<span id="cb2-2">year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2026</span></span>
<span id="cb2-3"></span>
<span id="cb2-4">text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">macro</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The current year is &amp;year"</span>)</span>
<span id="cb2-5"></span>
<span id="cb2-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># You can also combine multiple macro variables</span></span>
<span id="cb2-7">some_variable <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"current"</span></span>
<span id="cb2-8">current2026   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The current year is"</span></span>
<span id="cb2-9"></span>
<span id="cb2-10">text_combi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">macro</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&amp;&amp;some_variable&amp;year &amp;year"</span>)</span>
<span id="cb2-11"></span>
<span id="cb2-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Resolving macro variable in character vector</span></span>
<span id="cb2-13">char_vector <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The current year is &amp;year"</span>,</span>
<span id="cb2-14">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The &amp;some_variable year is &amp;year"</span>,</span>
<span id="cb2-15">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&amp;&amp;some_variable&amp;year &amp;year"</span>)</span>
<span id="cb2-16"></span>
<span id="cb2-17">text_vector <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply_macro</span>(char_vector)</span></code></pre></div></div>
</div>
</section>
<section id="filter-observations-and-variables-and-directly-view-the-result-on-screen." class="level1">
<h1>Filter observations and variables and directly view the result on screen.</h1>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb3-2">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb3-3"></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get a quick filtered view</span></span>
<span id="cb3-5">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where.</span>(sex <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,</span>
<span id="cb3-6">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(sex, age, household_id, education))</span></code></pre></div></div>
</div>
</section>
<section id="run-multiple-imports-and-exports" class="level1">
<h1>Run multiple imports and exports</h1>
<p><a href="https://s3rdia.github.io/qol/reference/import_export.html">import_multi</a> and <a href="https://s3rdia.github.io/qol/reference/import_export.html">export_multi</a> are based on the ‘SAS’ procedures Proc Import and Proc Export, which provide a very straight forward syntax. While ‘SAS’ can import many different formats with these procedures, these ‘R’ versions concentrate on importing CSV and XLSX files.</p>
<p>The main goal here is to just provide as few as possible parameters to tackle most of the imports and exports. These error handling also tries to let an import and export happen, even though a parameter wasn’t provided in the correct way.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example files</span></span>
<span id="cb4-2">csv_file  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"extdata"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol_example_data.csv"</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol"</span>)</span>
<span id="cb4-3">xlsx_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"extdata"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol_example_data.xlsx"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol"</span>)</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Import multiple files at once</span></span>
<span id="cb4-6">all_files <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_multi</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(csv_file, xlsx_file))</span>
<span id="cb4-7"></span>
<span id="cb4-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame list</span></span>
<span id="cb4-9">my_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb4-10">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">second =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb4-11"></span>
<span id="cb4-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export multiple data frames into one xlsx file</span></span>
<span id="cb4-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># with multiple sheets</span></span>
<span id="cb4-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">export_multi</span>(my_list, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempdir</span>())</span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export multiple data frames into multiple xlsx files</span></span>
<span id="cb4-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">export_multi</span>(my_list, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempdir</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">into_sheets =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb4-18"></span>
<span id="cb4-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export multiple data frames into multiple csv files</span></span>
<span id="cb4-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">export_multi</span>(my_list, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempdir</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">separator =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">";"</span>)</span></code></pre></div></div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>Update</category>
  <guid>https://your-website-url.example.com/posts/05. Update 1.2.1/</guid>
  <pubDate>Wed, 11 Feb 2026 23:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/05. Update 1.2.1/logo.png" medium="image" type="image/png" height="70" width="144"/>
</item>
<item>
  <title>qol 1.2.0: MASSIVE Update Makes It Its Own Ecosystem For Descriptive Evaluations And Data Wrangling</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/04. Update 1.2.0/</link>
  <description><![CDATA[ 






<p>With the newest update this package brings even more SAS functionalities to R and becomes its own ecosystem. So what’s in it?</p>
<ul>
<li>38 new functions, among other things a powerful transpose function, data frame content reports, global styling options, CSV and XLSX import and export and many more.</li>
<li>New functionalities for already established functions, like keeping/dropping variable ranges or generate a more interactive master file.</li>
<li>Further optimizations to make the code run faster, up to 40% in some places.</li>
<li>Some bug fixes and an even more robust error handling.</li>
</ul>
<p>An many more things. The full release notes can be seen <a href="https://github.com/s3rdia/qol/releases/tag/v1.2.0">here</a>.</p>
<section id="fast-and-powerful-yet-simple-to-use-transpose" class="level1">
<h1>Fast And Powerful Yet Simple To Use Transpose</h1>
<p><a href="https://s3rdia.github.io/qol/reference/transpose_plus.html">transpose_plus()</a> is just very loosely based on the ‘SAS’ procedure Proc Transpose, and the possibilities of a Data-Step transposition using loops.</p>
<p>The transposition methods ‘SAS’ has to offer are actually fairly weak. Which is weird because all tools are there to have another powerful function. So transpose_plus() tries to create the function ‘SAS’ should have.</p>
<p>The function is able to interpret which transposition direction the user wants by just looking at what the user provided with the function parameters. For a long to wide transposition it is natural to just provide variables to transpose. While it is also just natural to provide new variable names when transposing from wide to long. That alone reduces the number of parameters the user has to enter to perform a simple transposition.</p>
<p>The real magic happens when formats come into play. With their help you can not only name new variables or their expressions, but you can also generate completely new expressions with no effort, just with the help of multilabels.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example formats</span></span>
<span id="cb1-2">age. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb1-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb1-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb1-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb1-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb1-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb1-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb1-9"></span>
<span id="cb1-10">sex. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb1-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb1-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb1-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-14"></span>
<span id="cb1-15">sex2. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb1-16">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span>),</span>
<span id="cb1-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>,</span>
<span id="cb1-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span>)</span>
<span id="cb1-19"></span>
<span id="cb1-20">income. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interval_format</span>(</span>
<span id="cb1-21">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>              <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99999</span>,</span>
<span id="cb1-22">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"below 500"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">499</span>,</span>
<span id="cb1-23">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"500 to under 1000"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span>,</span>
<span id="cb1-24">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1000 to under 2000"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>,</span>
<span id="cb1-25">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2000 and more"</span>      <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99999</span>)</span>
<span id="cb1-26"></span>
<span id="cb1-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb1-28">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb1-29"></span>
<span id="cb1-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Transpose from long to wide and use a multilabel to generate additional categories</span></span>
<span id="cb1-31">long_to_wide <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-32">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, age),</span>
<span id="cb1-33">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education"</span>),</span>
<span id="cb1-34">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values   =</span> income,</span>
<span id="cb1-35">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb1-36">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight   =</span> weight,</span>
<span id="cb1-37">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm    =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-38"></span>
<span id="cb1-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Transpose back from wide to long</span></span>
<span id="cb1-40">wide_to_long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long_to_wide <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-41">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, age),</span>
<span id="cb1-42">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span>),</span>
<span id="cb1-43">                                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)))</span>
<span id="cb1-44"></span>
<span id="cb1-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Nesting variables in long to wide transposition</span></span>
<span id="cb1-46">nested <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-47">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, age),</span>
<span id="cb1-48">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + education"</span>,</span>
<span id="cb1-49">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values   =</span> income,</span>
<span id="cb1-50">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb1-51">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight   =</span> weight,</span>
<span id="cb1-52">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm    =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-53"></span>
<span id="cb1-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Or both, nested and un-nested, at the same time</span></span>
<span id="cb1-55">both <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-56">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, age),</span>
<span id="cb1-57">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + education"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education"</span>),</span>
<span id="cb1-58">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values   =</span> income,</span>
<span id="cb1-59">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb1-60">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight   =</span> weight,</span>
<span id="cb1-61">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm    =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
</section>
<section id="sort-data-frame-rows-with-some-additions" class="level1">
<h1>Sort Data Frame Rows With Some Additions</h1>
<p>Sort data frame rows by the provided variables. <a href="https://s3rdia.github.io/qol/reference/sort_plus.html">sort_plus</a> is also able to preserve the current order of certain variables and only sort other variables within this order. As another option one can sort a variable with the help of formats, which can be used to e.g.&nbsp;sort a character variable in another than alphabetical order without creating a temporary variable just for sorting.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example formats</span></span>
<span id="cb2-2">education. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb2-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>,</span>
<span id="cb2-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>,</span>
<span id="cb2-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)</span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb2-8">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simple sorting</span></span>
<span id="cb2-11">sort_df1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(state, sex, age))</span>
<span id="cb2-12">sort_df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(state, sex, age),</span>
<span id="cb2-13">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ascending"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"descending"</span>))</span>
<span id="cb2-14"></span>
<span id="cb2-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Character variables will normally be sorted alphabetically. With the help</span></span>
<span id="cb2-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># of a format this variable can be sorted in a completely different way.</span></span>
<span id="cb2-17">sort_df3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by      =</span> education,</span>
<span id="cb2-18">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.))</span>
<span id="cb2-19"></span>
<span id="cb2-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Preserve the order of the character variable, otherwise it couldn't stay in</span></span>
<span id="cb2-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># it's current order.</span></span>
<span id="cb2-22">sort_df4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sort_df3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by       =</span> age,</span>
<span id="cb2-23">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> education)</span></code></pre></div></div>
</div>
</section>
<section id="introducing-many-global-options-for-style-and-descriptions" class="level1">
<h1>Introducing Many Global Options For Style And Descriptions</h1>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_print</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the print option globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> the tabulation and export to Excel functions.</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_print</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored print option.</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_monitor</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the monitor option globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> the heavier functions which are able to show how they work internally.</span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_monitor</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored monitor option.</span>
<span id="cb3-8"></span>
<span id="cb3-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_na.rm</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the na.rm option globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> each <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> which can remove <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span> values.</span>
<span id="cb3-10"></span>
<span id="cb3-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_na.rm</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored na.rm option.</span>
<span id="cb3-12"></span>
<span id="cb3-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_print_miss</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the print_miss option globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> each <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> which can display missing categories.</span>
<span id="cb3-14"></span>
<span id="cb3-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_print_miss</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored print_miss option.</span>
<span id="cb3-16"></span>
<span id="cb3-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_output</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the output option globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> each <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> that can output results to <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"console"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel"</span> or <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel_nostyle"</span>.</span>
<span id="cb3-18"></span>
<span id="cb3-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_output</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored output option.</span>
<span id="cb3-20"></span>
<span id="cb3-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_titles</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the titles globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> each <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> that can print titles above the output table.</span>
<span id="cb3-22"></span>
<span id="cb3-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_titles</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored titles.</span>
<span id="cb3-24"></span>
<span id="cb3-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_footnotes</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Set the footnotes globally <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> each <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> that can print footnotes above the output table.</span>
<span id="cb3-26"></span>
<span id="cb3-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_footnotes</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Get the globally stored footnotes.</span></code></pre></div></div>
</div>
</section>
<section id="get-detailed-summary-about-a-data-frame" class="level1">
<h1>Get Detailed Summary About A Data Frame</h1>
<p><a href="https://s3rdia.github.io/qol/reference/content_report.html">content_report</a> is based on the ‘SAS’ procedure Proc Contents, which provides a summary of global information one one hand like number of observations and variables among many others and on the other hand shows per variable information like type and length.</p>
<p>‘R’ doesn’t store the same information in a data frame like ‘SAS’, but there are many useful information to get a quick overview of a data frame. With this function you don’t need to look at each variable individually. You can simply run it over a data frame and get values for: number of unique values, missing values (absolute and relative), min and max value as well as the top value.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb4-2">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb4-3"></span>
<span id="cb4-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_report</span>(my_data)</span></code></pre></div></div>
</div>
</section>
<section id="high-level-import-from-and-export-to-csv-and-xlsx" class="level1">
<h1>High Level Import From And Export To CSV And XLSX</h1>
<p><a href="https://s3rdia.github.io/qol/reference/import_export.html">import_data</a> and <a href="https://s3rdia.github.io/qol/reference/import_export.html">export_data</a> are based on the ‘SAS’ procedures Proc Import and Proc Export, which provide a very straight forward syntax. While ‘SAS’ can import many different formats with these procedures, these ‘R’ versions concentrate on importing CSV and XLSX files.</p>
<p>The main goal here is to just provide as few as possible parameters to tackle most of the imports and exports. These error handling also tries to let an import and export happen, even though a parameter wasn’t provided in the correct way.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example files</span></span>
<span id="cb5-2">csv_file  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"extdata"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol_example_data.csv"</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol"</span>)</span>
<span id="cb5-3">xlsx_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"extdata"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol_example_data.xlsx"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol"</span>)</span>
<span id="cb5-4"></span>
<span id="cb5-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Import: Provide full file path</span></span>
<span id="cb5-6">my_csv  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(csv_file)</span>
<span id="cb5-7">my_xlsx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(xlsx_file)</span>
<span id="cb5-8"></span>
<span id="cb5-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Import specific regions</span></span>
<span id="cb5-10">range_import <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(xlsx_file, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">region =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B4:H32"</span>)</span>
<span id="cb5-11">name_import  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(xlsx_file, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">region =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"test_region"</span>)</span>
<span id="cb5-12"></span>
<span id="cb5-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Import from another sheet</span></span>
<span id="cb5-14">sheet_import <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(xlsx_file, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sheet 2"</span>)</span>
<span id="cb5-15"></span>
<span id="cb5-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb5-17">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb5-18"></span>
<span id="cb5-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example export file paths</span></span>
<span id="cb5-20">export_csv  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fileext =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".csv"</span>)</span>
<span id="cb5-21">export_xlsx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fileext =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".xlsx"</span>)</span>
<span id="cb5-22"></span>
<span id="cb5-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export: Provide full file path</span></span>
<span id="cb5-24">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">export_data</span>(export_csv)</span>
<span id="cb5-25">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">export_data</span>(export_xlsx)</span>
<span id="cb5-26"></span>
<span id="cb5-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Manual cleanup for example</span></span>
<span id="cb5-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlink</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(export_csv, export_xlsx))</span></code></pre></div></div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>Update</category>
  <guid>https://your-website-url.example.com/posts/04. Update 1.2.0/</guid>
  <pubDate>Mon, 12 Jan 2026 23:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/04. Update 1.2.0/logo.png" medium="image" type="image/png" height="70" width="144"/>
</item>
<item>
  <title>A Further Comparison Of qol And SAS</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/03. Further compare/</link>
  <description><![CDATA[ 






<section id="checking-file-paths" class="level1">
<h1>Checking File Paths</h1>
<p>In SAS you have to assign Libraries to have access to a file path. When assigning a Library SAS directly checks, if the given path is valid. Additionally you can view all the SAS data files in the user interface, which are available in a Library:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">Libname MyData <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C\:My_Path</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</div>
<p>qol also implements a <code>libname()</code> function, which basically does a little check on the given path and informs you with the result:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Check if path exists</span></span>
<span id="cb2-2">my_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">libname</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C/:My_Path/"</span>)</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Retrieve a named character vector of full file paths</span></span>
<span id="cb2-5">my_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">libname</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C/:My_Path/"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">get_files =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
</section>
<section id="stacking-datasets" class="level1">
<h1>Stacking datasets</h1>
<p>Stacking up datasets can be as easy and readable as this in SAS:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">Data Work.NewDataSet;</span>
<span id="cb3-2">    Set Work.MyData1</span>
<span id="cb3-3">        Work.MyData2</span>
<span id="cb3-4">        Work.MyData3;</span>
<span id="cb3-5">Run;</span></code></pre></div></div>
</div>
<p>qol does it just as readable:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">NewDataSet <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(MyData1,</span>
<span id="cb4-2">                  MyData2,</span>
<span id="cb4-3">                  MyData3)</span></code></pre></div></div>
</div>
</section>
<section id="more-than-just-if" class="level1">
<h1>More Than Just ‘if’</h1>
<p>SAS makes use of if-statements like most other languages do. The most common use case should be to generate a new variable or to be more specific: to assign a value to a variable conditionally. Inside a Data-Step you can write single if-statements or connect multiple to a whole block. You can also make use of ‘else if’, which is only executed, if no other if-condition from before was true. And there is ‘else’ which is executed, if no other condition in a block became true.</p>
<p>Here is a simple if-block in a SAS Data-Step, which is used to generate groups of ages:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">Data Work.MyData_AgeGr;</span>
<span id="cb5-2">    Set Work.MyData;</span>
<span id="cb5-3"></span>
<span id="cb5-4">             If       Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> Then AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>;</span>
<span id="cb5-5">        Else If <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> Then AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>;</span>
<span id="cb5-6">        Else If <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span> Then AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>;</span>
<span id="cb5-7">        Else If <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span> Then AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>;</span>
<span id="cb5-8">        Else                        AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>;</span>
<span id="cb5-9"></span>
<span id="cb5-10">Run;</span></code></pre></div></div>
</div>
<p>The equivalent in R looks like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">MyData_AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb6-2">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>,             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AgeGr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_if.</span>(Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AgeGr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_if.</span>(Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AgeGr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_if.</span>(Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AgeGr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>   (                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AgeGr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span></code></pre></div></div>
</div>
<p>In SAS you can do more than just conditionally assigning a value to a variable with an if-statement. If you use the condition with ‘Then Do’, you can generate multiple variables like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">Data Work.MyData_Do;</span>
<span id="cb7-2">    Set Work.MyData;</span>
<span id="cb7-3"></span>
<span id="cb7-4">        If a <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> Then Do;</span>
<span id="cb7-5"></span>
<span id="cb7-6">            b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>;</span>
<span id="cb7-7">            c <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hello"</span>;</span>
<span id="cb7-8">            d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>;</span>
<span id="cb7-9"></span>
<span id="cb7-10">        End;</span>
<span id="cb7-11"></span>
<span id="cb7-12">Run;</span></code></pre></div></div>
</div>
<p>With the qol-Package you can write:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">MyData_Do <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-2">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(a <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb8-3">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hello"</span>,</span>
<span id="cb8-4">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)</span></code></pre></div></div>
</div>
<p>In both programs you can also connect further ‘else if’ and ‘else’-statements. And there is yet another function ‘if’ can do in SAS: you can use it to filter observations. This function takes action, if only the condition without any ‘Then’ is provided like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">Data Work.MyData_If;</span>
<span id="cb9-2">    Set Work.MyData;</span>
<span id="cb9-3"></span>
<span id="cb9-4">        <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Which means<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> only keep the observations,</span>
<span id="cb9-5">           which are true on the following condition. <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb9-6">        If Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span>;</span>
<span id="cb9-7"></span>
<span id="cb9-8">        <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Or you could just do this, which means<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> only</span>
<span id="cb9-9">           keep observations, where weight is not missing. <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb9-10">        If Weight;</span>
<span id="cb9-11"></span>
<span id="cb9-12">Run;</span></code></pre></div></div>
</div>
<p>The new <code>if.()</code> makes this possible, too:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">MyData_If <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(weight)</span></code></pre></div></div>
</div>
<p>Simple, readable and multi-functional.</p>
</section>
<section id="recoding-with-formats" class="level1">
<h1>Recoding With Formats</h1>
<p>Normally, if you want to recode a variable into new categories, you would probably do it with if-statements as seen above. With SAS formats you can achieve the same, just simpler and more readable:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">Proc Format Library <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work;</span>
<span id="cb11-2"></span>
<span id="cb11-3">    Value AgeGroup</span>
<span id="cb11-4">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'under 18'</span></span>
<span id="cb11-5">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'18 to under 25'</span></span>
<span id="cb11-6">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'25 to under 55'</span></span>
<span id="cb11-7">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'55 to under 65'</span></span>
<span id="cb11-8">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'65 and older'</span>;</span>
<span id="cb11-9"></span>
<span id="cb11-10">Run;</span>
<span id="cb11-11"></span>
<span id="cb11-12">Data Work.MyData_Recode;</span>
<span id="cb11-13">    Set Work.MyData;</span>
<span id="cb11-14"></span>
<span id="cb11-15">        AgeGr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Put</span>(Age, AgeGroup.);</span>
<span id="cb11-16"></span>
<span id="cb11-17">Run;</span></code></pre></div></div>
</div>
<p>Now you can do the same in R with <code>recode()</code> just as easy:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">AgeGroup. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb12-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb12-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb12-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb12-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb12-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>)</span>
<span id="cb12-7"></span>
<span id="cb12-8">MyData[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AgeGr"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AgeGroup."</span>)</span></code></pre></div></div>
</div>
</section>
<section id="the-world-of-retain" class="level1">
<h1>The World Of Retain</h1>
<p>On a very basic level ‘Retain’ can do two things, depending on the position in the SAS code: It can either sort variables column wise or it can - since it works row wise - remember a value from one row to the next. The newly implemented functions concentrate on the second part. Remembering a value from a previous observation offers multiple use cases. E.g. always adding +1 to the previous case creates a running number or adding different values can create a cumulative sum:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">Data Work.MyData_Retain;</span>
<span id="cb13-2">    Set Work.MyData;</span>
<span id="cb13-3"></span>
<span id="cb13-4">        Retain RunningNr <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> CumulativeIncome <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>;</span>
<span id="cb13-5"></span>
<span id="cb13-6">        RunningNr        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> RunningNr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>;</span>
<span id="cb13-7">        CumulativeIncome <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> CumulativeIncome <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Income;</span>
<span id="cb13-8"></span>
<span id="cb13-9">Run;</span></code></pre></div></div>
</div>
<p>qol doesn’t mimic the behavior of ‘Retain’, but rather the result:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">MyData[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"run_nr"</span>]]           <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">running_number</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb14-2">MyData[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CumulativeIncome"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">retain_sum</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> income)</span></code></pre></div></div>
</div>
<p>In it’s simplest form it can remember a value from the first observation and transfer it to all other observations:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">Data Work.MyData_Value;</span>
<span id="cb15-2">    Set Work.MyData;</span>
<span id="cb15-3"></span>
<span id="cb15-4">        Retain MyValue <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>;</span>
<span id="cb15-5"></span>
<span id="cb15-6">        If _n_ <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> Then MyValue <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Income;</span>
<span id="cb15-7"></span>
<span id="cb15-8">Run;</span></code></pre></div></div>
</div>
<p>qol does it like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1">MyData[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MyValue"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">retain_value</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> income)</span></code></pre></div></div>
</div>
<p>Not directly ‘Retain’ related, but also useful: If an observation knows the value of the previous one, it can check whether it is of the same value or another, e.g.&nbsp;to mark first or last cases within a group.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">Data Work.MyData_FirstLast;</span>
<span id="cb17-2">    Set Work.MyData;</span>
<span id="cb17-3"></span>
<span id="cb17-4">        By AgeGr;</span>
<span id="cb17-5">    </span>
<span id="cb17-6">            If First.AgeGr Then FirstCase <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>;</span>
<span id="cb17-7">            If Last.AgeGr  Then LastCase  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>;</span>
<span id="cb17-8"></span>
<span id="cb17-9">Run;</span></code></pre></div></div>
</div>
<p>qol creates this effect like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">MyData[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FirstCase"</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mark_case</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> AgeGr)</span>
<span id="cb18-2">MyData[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LastCase"</span>]]  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mark_case</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> AgeGr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</div>
<p>All of these functions work on the whole data frame as well as on groups, e.g.&nbsp;to transfer a value from the first person in a household to all other persons of the same household.</p>
</section>
<section id="join-them-all" class="level1">
<h1>Join Them All</h1>
<p>In a SAS Data-Step you can join multiple datasets together in a single operation using ‘Merge’ with a very basic syntax. Provide the dataset names, the variables, on which they should be joined and after a full join is complete, the user can decide which parts of the joins should remain in the final dataset:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">Data Work.MyData_Merged;</span>
<span id="cb19-2">    Merge <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Work.MyData_A</span> (<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">in =</span> a)</span>
<span id="cb19-3">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Work.MyData_B</span> (<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">in =</span> b)</span>
<span id="cb19-4">          Work.MyData_C;</span>
<span id="cb19-5"></span>
<span id="cb19-6">        By a b c d e;</span>
<span id="cb19-7">          </span>
<span id="cb19-8">          <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Here are examples of how the different joins can be selected,</span>
<span id="cb19-9">             making use of the above assigned <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>variables. <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-10">          If a;             <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> left join <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-11">          If b;             <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> right join <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-12">          If a And b;       <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> inner join <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-13">          If <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Not</span> (a And b); <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> outer join <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-14">          If a and Not b;   <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> left inner join <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-15">          If Not a And b;   <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> right inner join <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-16">                            <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/*</span> full join happens <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> no selection is specified <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb19-17"></span>
<span id="cb19-18">Run;</span></code></pre></div></div>
</div>
<p>The R equivalent <code>multi_join()</code> tries to keep the simplicity, while giving the user the power, to do more joins at the same time. Additionally to what Merge can do, this function also makes use of the Proc SQL possibility to join datasets on different variable names:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">MyData_Merged <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">multi_join</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_frames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(MyData_A, MyData_B, MyData_C),</span>
<span id="cb20-2">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">on  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"e"</span>)</span>
<span id="cb20-3">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">how =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb20-4"></span>
<span id="cb20-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Instead of "left" you can assign any of the above join methods.</span></span>
<span id="cb20-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># To join on differently named variables, you can write the function like this:</span></span>
<span id="cb20-7"></span>
<span id="cb20-8">MyData_Merged <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">multi_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(MyData_A, MyData_B, MyData_C),</span>
<span id="cb20-9">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">on =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MyData_A =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>),</span>
<span id="cb20-10">                                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MyData_B =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var2"</span>),</span>
<span id="cb20-11">                                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MyData_C =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"key1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"key2"</span>)))</span></code></pre></div></div>
</div>
</section>
<section id="splitting-datasets" class="level1">
<h1>Splitting Datasets</h1>
<p>SAS is capable of splitting up a dataset into multiple new ones. With the ‘Output’ function one can - among other things - explicitly tell SAS which observation to output into which dataset. Instead of subsetting the same dataset multiple times manually, you can subset it multiple times at once:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">Data Work.MyData_Male</span>
<span id="cb21-2">     Work.MyData_Female;</span>
<span id="cb21-3">    Set Work.MyData;</span>
<span id="cb21-4"></span>
<span id="cb21-5">             If Sex <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> Then Output Work.MyData_Male;</span>
<span id="cb21-6">        Else If Sex <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> Then Output Work.MyData_Female;</span>
<span id="cb21-7"></span>
<span id="cb21-8">Run;</span></code></pre></div></div>
</div>
<p>qol offers the function <code>split_by()</code> which split up data frames into a list of multiple new ones:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Using just the expressions of a single variable</span></span>
<span id="cb22-2">MyData_List <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split_by</span>(Sex)</span>
<span id="cb22-3"></span>
<span id="cb22-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Or using conditions</span></span>
<span id="cb22-5">MyData_List <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split_by</span>(Sex <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>,</span>
<span id="cb22-6">                                  Sex <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>)</span></code></pre></div></div>
</div>
</section>
<section id="keepdrop" class="level1">
<h1>Keep/Drop</h1>
<p>In SAS ‘Keep’ and ‘Drop’ share the same writing style and don’t require a minus sign (in case of ‘Drop’). There are also some additions which can make keeping or dropping ranges of variables easier:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">Data Work.MyData_KeepDrop;</span>
<span id="cb23-2">    Set Work.MyData;</span>
<span id="cb23-3"></span>
<span id="cb23-4">        Keep a b c d;</span>
<span id="cb23-5">        Drop a b c d;</span>
<span id="cb23-6"></span>
<span id="cb23-7">        <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> When you have to keep or drop many variables you can also define a range <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb23-8">        Keep start_var <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">--</span> end_var; <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Keep every variable between the two given <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ones</span> (including them) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb23-9">        Drop start_var <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">--</span> end_var; <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Drop every variable between the two given <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ones</span> (including them) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb23-10"></span>
<span id="cb23-11">        <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/*</span> You can also keep or drop variables based on what characters they start with <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb23-12">        Keep var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>; <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Keep every variable starting with <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb23-13">        Drop var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>; <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Drop every variable starting with <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb23-14"></span>
<span id="cb23-15">Run;</span></code></pre></div></div>
</div>
<p>The qol <code>keep()</code> and <code>dropp()</code> (drop was already taken, so the additional p is intentional ;-) ), are written alike:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">keep</span>(a, b, c, d)</span>
<span id="cb24-2">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dropp</span>(a, b, c, d)</span>
<span id="cb24-3"></span>
<span id="cb24-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ranges can be used like this</span></span>
<span id="cb24-5">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">keep</span>(start_var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>end_var)</span>
<span id="cb24-6">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dropp</span>(start_var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>end_var)</span>
<span id="cb24-7"></span>
<span id="cb24-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The R version not only provides the option to select variables "starting with"</span></span>
<span id="cb24-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># certain characters but also "ending with" and "containing". The colon ":" acts</span></span>
<span id="cb24-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># as a placeholder.</span></span>
<span id="cb24-11">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">keep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var:"</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Start with</span></span>
<span id="cb24-12">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">keep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":var"</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># End with</span></span>
<span id="cb24-13">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">keep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":var:"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Contains</span></span>
<span id="cb24-14"></span>
<span id="cb24-15">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dropp</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var:"</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Start with</span></span>
<span id="cb24-16">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dropp</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":var"</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># End with</span></span>
<span id="cb24-17">MyData_KeepDrop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dropp</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":var:"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Contains</span></span></code></pre></div></div>
</div>
</section>
<section id="more-on-tabulation" class="level1">
<h1>More On Tabulation</h1>
<p>Sometimes you probably don’t want to create a big, fully styled table and just need a small and basic one for a quick overview. The SAS procedure Proc Freq offers tools to produce simple frequencies of single variables. The code is as straight forward as this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">Proc Freq Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData;</span>
<span id="cb25-2"></span>
<span id="cb25-3">    Table Age;</span>
<span id="cb25-4"></span>
<span id="cb25-5">Run;</span></code></pre></div></div>
</div>
<p>The function <code>frequencies()</code> does the same like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># You can just output a quick ASCII style table in the console</span></span>
<span id="cb26-2">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frequencies</span>(Age)</span>
<span id="cb26-3"></span>
<span id="cb26-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Or a fully styled Excel table like this</span></span>
<span id="cb26-5">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frequencies</span>(Age, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel"</span>)</span></code></pre></div></div>
</div>
<p>Proc Freq is also capable of producing cross tables. Just an asterisk between two variables is neccessary:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">Proc Freq Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData;</span>
<span id="cb27-2"></span>
<span id="cb27-3">    Table Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> Sex;</span>
<span id="cb27-4"></span>
<span id="cb27-5">Run;</span></code></pre></div></div>
</div>
<p>To reproduce this, the function <code>crosstabs()</code> comes into play:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Again in ASCII style</span></span>
<span id="cb28-2">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crosstabs</span>(Age, Sex)</span>
<span id="cb28-3"></span>
<span id="cb28-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Or in the fully styled Excel version</span></span>
<span id="cb28-5">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crosstabs</span>(Age, Sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel"</span>)</span>
<span id="cb28-6"></span>
<span id="cb28-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># By the way: if you want to produce multiple structurally identical tables</span></span>
<span id="cb28-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># by the expressions of another variable, you can do so like this:</span></span>
<span id="cb28-9">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frequencies</span>(Age, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> Education)</span>
<span id="cb28-10">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crosstabs</span>(Age, Sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> Education)</span></code></pre></div></div>
</div>
<p>There are several options to customize the output tables. You can for example add titles and footnotes or put some labels on the variable expressions:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">Proc Format Library <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work;</span>
<span id="cb29-2"></span>
<span id="cb29-3">    Value AgeGroup</span>
<span id="cb29-4">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'under 18'</span></span>
<span id="cb29-5">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'18 to under 25'</span></span>
<span id="cb29-6">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'25 to under 55'</span></span>
<span id="cb29-7">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'55 to under 65'</span></span>
<span id="cb29-8">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'65 and older'</span>;</span>
<span id="cb29-9"></span>
<span id="cb29-10">Run;</span>
<span id="cb29-11"></span>
<span id="cb29-12">Title1    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is a title"</span>;</span>
<span id="cb29-13">Footnote1 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is a footnote"</span>;</span>
<span id="cb29-14">        </span>
<span id="cb29-15">Proc Freq Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData;</span>
<span id="cb29-16"></span>
<span id="cb29-17">    Table Age;</span>
<span id="cb29-18">        </span>
<span id="cb29-19">    Format Age AgeGroup.;</span>
<span id="cb29-20"></span>
<span id="cb29-21">Run;</span></code></pre></div></div>
</div>
<p>And in R you do it like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">AgeGroup. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb30-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb30-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb30-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb30-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb30-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>)</span>
<span id="cb30-7"></span>
<span id="cb30-8">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frequencies</span>(Age,</span>
<span id="cb30-9">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats   =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age =</span> AgeGroup.),</span>
<span id="cb30-10">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">titles    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is a title"</span>,</span>
<span id="cb30-11">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">footnotes =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is a footnote"</span>)</span></code></pre></div></div>
</div>
</section>
<section id="export-data-frames-with-style" class="level1">
<h1>Export Data Frames With Style</h1>
<p>There are occasions when you don’t want to tabulate your data, but just print out the data frame you put together. There are multiple ways to do this, Proc Export is probably the most straight forward one:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1">Proc Export Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData;</span>
<span id="cb31-2"></span>
<span id="cb31-3">    Outfile <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:\MyFile.xlsx"</span>;</span>
<span id="cb31-4">    DBMS <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> xlsx;</span>
<span id="cb31-5"></span>
<span id="cb31-6">Run;</span></code></pre></div></div>
</div>
<p>This in itself is no revolution, many R packages already can do this. But to combine the simplicity of this export with the simplicity of the already established styling options from the tabulation functions, offers new options:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">export_with_style</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">titles    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is a title"</span>,</span>
<span id="cb32-2">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">footnotes =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is a footnote"</span>,</span>
<span id="cb32-3">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">excel_output_style</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header_back_color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0000FF"</span>,</span>
<span id="cb32-4">                                                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header_font_color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FF0000"</span>,</span>
<span id="cb32-5">                                                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font              =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Times New Roman"</span>,</span>
<span id="cb32-6">                                                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title_font_size   =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span></code></pre></div></div>
</div>
<p>By the way: All tabulation functions and the above export function from the qol package generate the named regions ‘table’ and ‘data’ in the Excel output, which can easily be read back in with the help of the <a href="https://github.com/JanMarvin/openxlsx2">openxlsx2</a> package:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1">MyData <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wb_to_df</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:/MyFile.xlsx"</span>,</span>
<span id="cb33-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb33-3">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">named_region =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>)</span></code></pre></div></div>
</div>
</section>
<section id="import-csv-and-xlsx-files" class="level1">
<h1>Import CSV And XLSX Files</h1>
<p>With SAS you can import many different file formats with a straight forward syntax:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> For CVS <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb34-2">Proc Import</span>
<span id="cb34-3"></span>
<span id="cb34-4">    Datafile <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:\MyFile.csv"</span></span>
<span id="cb34-5">    Out      <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData</span>
<span id="cb34-6">    DBMS     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> csv;</span>
<span id="cb34-7"></span>
<span id="cb34-8">Run;</span>
<span id="cb34-9"></span>
<span id="cb34-10"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> For XLSX <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb34-11">Proc Import</span>
<span id="cb34-12"></span>
<span id="cb34-13">    Datafile <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:\MyFile.xlsx"</span></span>
<span id="cb34-14">    Out      <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData</span>
<span id="cb34-15">    DBMS     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> xlsx;</span>
<span id="cb34-16"></span>
<span id="cb34-17">Run;</span></code></pre></div></div>
</div>
<p>The R versions concentrate on importing CSV and XLSX files:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1">csv_file  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:\MyFile.csv"</span>)</span>
<span id="cb35-2">xlsx_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">import_data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:\MyFile.xlsx"</span>)</span></code></pre></div></div>
</div>
<p>Note: There is also an export function which can export CSV and XLSX files without any style:</p>
</section>
<section id="information-about-datasets" class="level1">
<h1>Information About Datasets</h1>
<p>To get a quick overview of a dataset, SAS provides an easy way to get a short report. This report contains global information like, number of variables and observations but also information per variable like the type and length:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> For CVS <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb36-2">Proc Contents Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.MyData;</span>
<span id="cb36-3">Run;</span></code></pre></div></div>
</div>
<p>A data frame in R doesn’t store the same information like a SAS dataset but one can get quiet a few information out of it like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1">MyData <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_report</span>()</span></code></pre></div></div>
</div>
</section>
<section id="transposing" class="level1">
<h1>Transposing</h1>
<p>The SAS transpose procedure is very basic, but it knows in which direction the user wants to transpose by just providing certain parameters:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Long to wide <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb38-2">Proc Transpose Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.Long</span>
<span id="cb38-3">                Out <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.Wide;</span>
<span id="cb38-4"></span>
<span id="cb38-5">    By Age;</span>
<span id="cb38-6"></span>
<span id="cb38-7">    Var Income;</span>
<span id="cb38-8"></span>
<span id="cb38-9">    ID Sex;</span>
<span id="cb38-10"></span>
<span id="cb38-11">Run;</span>
<span id="cb38-12"></span>
<span id="cb38-13"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Wide to long <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb38-14">Proc Transpose Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.Wide</span>
<span id="cb38-15">                Out <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Work.Long</span> (<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Rename =</span> (<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">_NAME_ =</span> Sex));</span>
<span id="cb38-16"></span>
<span id="cb38-17">    By Age;</span>
<span id="cb38-18"></span>
<span id="cb38-19">    Var Male Female;</span>
<span id="cb38-20"></span>
<span id="cb38-21">Run;</span></code></pre></div></div>
</div>
<p>The R version in this package actually can do way more than just a simple transposition. Here is just a basic example, for what it can do additionally, have a look at the reference on <a href="https://s3rdia.github.io/qol/reference/transpose_plus.html">transpose_plus</a>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wide to long</span></span>
<span id="cb39-2">wide <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb39-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> age,</span>
<span id="cb39-4">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>,</span>
<span id="cb39-5">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values   =</span> income)</span>
<span id="cb39-6"></span>
<span id="cb39-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Long to wide</span></span>
<span id="cb39-8">long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> wide <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb39-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> age,</span>
<span id="cb39-10">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span>)))</span></code></pre></div></div>
</div>
</section>
<section id="macro-variables" class="level1">
<h1>Macro Variables</h1>
<p>Macro variables in ‘SAS’ can be set up with %Let and can act as global accessible variables. Among other use cases macro variables can be resolved within texts, which can come in handy in e.g.&nbsp;titles and footnotes:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">%Let year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2026</span>;</span>
<span id="cb40-2"></span>
<span id="cb40-3">Title1 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The current year is &amp;year"</span>;</span></code></pre></div></div>
</div>
<p>The R version looks basically the same:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1">year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2026</span></span>
<span id="cb41-2"></span>
<span id="cb41-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_titles</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The current year is &amp;year"</span>)</span></code></pre></div></div>
</div>
<p>These are just very basic examples. For further details you can look up the functions in the <a href="https://s3rdia.github.io/qol/reference/index.html">reference</a>.</p>


</section>

 ]]></description>
  <category>R</category>
  <category>Showcase</category>
  <guid>https://your-website-url.example.com/posts/03. Further compare/</guid>
  <pubDate>Sun, 30 Nov 2025 23:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/03. Further compare/logo.png" medium="image" type="image/png" height="70" width="144"/>
</item>
<item>
  <title>Powerful tabulation thanks to SAS concepts</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/02. SAS compare/</link>
  <description><![CDATA[ 






<p>SAS is a flagship when it comes to creating massive descriptive tables with little effort, because it offers the right tools. This package tries to adapt some of these to also make them available in R.</p>
<section id="the-concept-of-formats" class="level1">
<h1>The Concept of Formats</h1>
<p>Formats are like molds or stencils to put the data through. In SAS formats are defined with the procedure Proc Formats, which is adapted with <code>discrete_format()</code> and <code>interval_format()</code>. Here you can define, which values should be transferred into which result categories. This is completely detached from the data your working with.</p>
<p>The great thing about this is, that one can not only label and recode values, but one can also define so called multilabels. Meaning, one original value can be transferred into multiple result categories.</p>
<p>A cell in a data frame can only hold one distinct value, which is normally a good thing. But let’s say you want to convert single ages into age categories. The age “3” for example could go into the category “under 6”, but also in “under 12”, “under 18” and “total”. Normally you would compute additional variables, which hold the different categorizations, or you could also double up the observations for each category. Both ways would just bloat up the data frame and cost additional memory, particularly if you work with big data sets.</p>
<p>With these format containers, you just keep a small reference of original values and result categories. Formats and data find their way together only just before computing the results, meaning the original data frame can be passed into a function capable of handling formats, without any data transformation beforehand. You just tell the function which format should be applied to which variable. That’s it. The function handles the rest and outputs all the desired categories.</p>
<p>This method is very memory efficient, readable and user friendly for creating larger and more complex outputs at the same time.</p>
<p>Let’s look at how formats are created in SAS:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">Proc Format;</span>
<span id="cb1-2"></span>
<span id="cb1-3">    Value <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sex</span> (Multilabel Notsorted)</span>
<span id="cb1-4">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Total'</span></span>
<span id="cb1-5">          <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Male'</span></span>
<span id="cb1-6">          <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Female'</span>;</span>
<span id="cb1-7">          </span>
<span id="cb1-8">    Value <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Age</span> (Multilabel Notsorted)</span>
<span id="cb1-9">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Total'</span></span>
<span id="cb1-10">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">02</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'under 3'</span></span>
<span id="cb1-11">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'under 6'</span></span>
<span id="cb1-12">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'under 12'</span></span>
<span id="cb1-13">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">00</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'under 18'</span></span>
<span id="cb1-14">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'18 to under 25'</span></span>
<span id="cb1-15">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'25 to under 55'</span></span>
<span id="cb1-16">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'55 to under 65'</span></span>
<span id="cb1-17">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'65 and older'</span></span>
<span id="cb1-18">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'80 and older'</span>;</span>
<span id="cb1-19"></span>
<span id="cb1-20">Run;</span></code></pre></div></div>
</div>
<p>The equivalent in R now looks like this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">sex. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb2-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb2-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb2-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb2-5">    </span>
<span id="cb2-6">age. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb2-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>,</span>
<span id="cb2-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 3"</span>        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb2-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 6"</span>        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb2-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 12"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>,</span>
<span id="cb2-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb2-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb2-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb2-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb2-15">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>,</span>
<span id="cb2-16">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"80 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>)</span></code></pre></div></div>
</div>
<p>The main difference is that input and output values are swapped, but that aside it looks very similar. I would recommend to let format names end with a dot to make them stand out. The dot at the end is the SAS way of assigning a format to a variable.</p>
</section>
<section id="a-more-powerful-summarise" class="level1">
<h1>A More Powerful Summarise</h1>
<p><code>summarise_plus()</code> is based on the SAS procedure Proc Summary, which provides efficient and readable ways to perform complex aggregations.</p>
<p>Normally you would compute new categorical variables beforehand - probably even in different forms, if you wanted to have different categorizations - and bloat up the data set. After all this recoding footwork you could finally use multiple summaries to compute all the stats you need to then put them back together. With this function this is no more necessary.</p>
<p>In <code>summarise_plus()</code> you put in the original data frame and let the recoding happen via format containers. This is very efficient, since new variables and categories are only created just before the summarise happens.</p>
<p>Additionally you can specify whether you only want to produce the all nested version of all group variables or whether you want to produce every possible combination in one go. All with a single option.</p>
<p>First of all let’s look at it from the SAS side:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">Proc Summary Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.My_Data;</span>
<span id="cb3-2"></span>
<span id="cb3-3">    Class Year;</span>
<span id="cb3-4">    Class Sex Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Order <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Data Mlf Preloadfmt Missing;</span>
<span id="cb3-5"></span>
<span id="cb3-6">    Var Weight;</span>
<span id="cb3-7"></span>
<span id="cb3-8">    Format Sex Sex. Age Age.;</span>
<span id="cb3-9"></span>
<span id="cb3-10">    Output Out  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.My_Data_Agg</span>
<span id="cb3-11">           Sum  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span></span>
<span id="cb3-12">           Mean <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>;</span>
<span id="cb3-13"></span>
<span id="cb3-14">Run;</span></code></pre></div></div>
</div>
<p>The equivalent in R would be this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">my_data_agg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class      =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, sex, age),</span>
<span id="cb4-3">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb4-4">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"freq"</span>),</span>
<span id="cb4-5">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex.,</span>
<span id="cb4-6">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb4-7">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nesting    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>,</span>
<span id="cb4-8">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<p>Again I tried to keep it as close as possible to the original. What both functions do, is to generate every possible combination of the class variables. Meaning:</p>
<ul>
<li>total</li>
<li>year</li>
<li>sex</li>
<li>age</li>
<li>year + sex</li>
<li>year + age</li>
<li>sex + age</li>
<li>year + sex + age</li>
</ul>
<p>In addition, because we are using formats, the function not only generates the results for the original (labeled) values, but also for the additional categories specified in the multilabels above. To make it simple: You put in the variable sex with the values of 1 and 2 from the original data and get the results for “Male”, “Female” and “Total” (meaning 1 + 2). With this approach you can keep the original data as original as possible and only generate the desired variables and values during summarisation. And if you only would like the combination of year + sex + age, as you would get from any other summarisation function, you can just change nesting to “deepest”. In SAS you would just add NWay to the end of the first line.</p>
</section>
<section id="a-more-powerful-tabulation" class="level1">
<h1>A More Powerful Tabulation</h1>
<p><code>any_table()</code> is based on the SAS procedure Proc Tabulate, which provides efficient and readable ways to perform complex tabulations.</p>
<p>With this function you can combine any number of variables in any possible way, all at once. Sounds crazy? Is crazy! You just define which variables or variable combinations should end up in the table rows and columns with a simple syntax. Listing variables in a vector like c(“var1”, “var2”, “var3”,…) means to put variables below (in case of the row variables) or besides (in case of the column variables) each other. Nesting variables is as easy as putting a plus sign between them, e.g.&nbsp;c(“var1 + var2”, “var2” + “var3” + “var4”, etc.). And of course you can combine both versions.</p>
<p>The real highlight is, that this function not only creates all the desired variable combinations and exports them to an Excel file, it prints a fully custom styled table to a workbook. Setting up a custom, reusable style is as easy as setting up options like: provide a color for the table header, set the font size for the row header, should borders be drawn for the table cells yes/no, and so on. Merging doubled header texts, happens automatically.</p>
<p>With this function you basically can fully concentrate on designing a table, instead of thinking hard about how to calculate where to put a border or to even manually prepare a designed workbook.</p>
<p>Again, the SAS way first:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">Proc Tabulate Data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Work.Armut;</span>
<span id="cb5-2"></span>
<span id="cb5-3">    Class Year;</span>
<span id="cb5-4">    Class Sex Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Order <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> Data Mlf Preloadfmt;</span>
<span id="cb5-5"></span>
<span id="cb5-6">    Var Weight;</span>
<span id="cb5-7"></span>
<span id="cb5-8">    Table <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Rows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb5-9">          Sex <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span></span>
<span id="cb5-10">          Sex <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> Alter <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span>,</span>
<span id="cb5-11"></span>
<span id="cb5-12">          <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span> Columns <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb5-13">          Year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Percentage based on sex'</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> Weight <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> PctSum<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>sex<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'%'</span></span>
<span id="cb5-14">          Year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Population (weighted)'</span>   <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> Weight <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> Sum <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'1000'</span></span>
<span id="cb5-15">          Year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Unweighted'</span>              <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> Weight <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Count'</span></span>
<span id="cb5-16">          <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Box <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Variable'</span>;</span>
<span id="cb5-17"></span>
<span id="cb5-18">    Format Sex Sex. Age Age.;</span>
<span id="cb5-19"></span>
<span id="cb5-20">Run;</span></code></pre></div></div>
</div>
<p>The equivalent in R would be this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + age"</span>),</span>
<span id="cb6-2">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,</span>
<span id="cb6-3">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb6-4">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"freq"</span>),</span>
<span id="cb6-5">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_group  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>,</span>
<span id="cb6-6">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex.,</span>
<span id="cb6-7">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb6-8">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<p>In this function the way of writing things goes a bit apart, but the core mechanics, to achieve the same result, stay the same. This is just a simple example, but you can nest any number of variables, anywhere in the table. With the help of formats you can generate any number of additional categories without touching the original data. And it doesn’t get more complex than what you see above. Don’t believe me?</p>
<p>What should we do, if we wanted to produce the same table multiple times, but every time filtered by an expression of another variable? I need to write some fancy loops, right? … right? Give me a second:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Let's try it with the single states of Germany, Germany as a whole</span></span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># and eastern and western states.</span></span>
<span id="cb7-3">state. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb7-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Germany"</span>                       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>,</span>
<span id="cb7-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Schleswig-Holstein"</span>            <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb7-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hamburg"</span>                       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb7-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower Saxony"</span>                  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb7-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bremen"</span>                        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb7-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"North Rhine-Westphalia"</span>        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb7-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hesse"</span>                         <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb7-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rhineland-Palatinate"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,</span>
<span id="cb7-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Baden-Württemberg"</span>             <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,</span>
<span id="cb7-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bavaria"</span>                       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,</span>
<span id="cb7-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saarland"</span>                      <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb7-15">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West"</span>                          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb7-16">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Berlin"</span>                        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>,</span>
<span id="cb7-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brandenburg"</span>                   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>,</span>
<span id="cb7-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mecklenburg-Western Pomerania"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>,</span>
<span id="cb7-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saxony"</span>                        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>,</span>
<span id="cb7-20">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saxony-Anhalt"</span>                 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,</span>
<span id="cb7-21">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Thuringia"</span>                     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>,</span>
<span id="cb7-22">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"East"</span>                          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb7-23"></span>
<span id="cb7-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Now produce the same table as above for every expression of the format above.</span></span>
<span id="cb7-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># See the difference? There is nothing more to it.</span></span>
<span id="cb7-26">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + age"</span>),</span>
<span id="cb7-27">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,</span>
<span id="cb7-28">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by         =</span> state,</span>
<span id="cb7-29">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb7-30">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"freq"</span>),</span>
<span id="cb7-31">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_group  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>,</span>
<span id="cb7-32">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex   =</span> sex.,</span>
<span id="cb7-33">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age   =</span> age.,</span>
<span id="cb7-34">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state =</span> state.),</span>
<span id="cb7-35">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<p>With the above code you get an Excel workbook with 19 worksheets containing the same table for the different states. By the way: SAS can do the same just as easy.</p>
</section>
<section id="do-it-with-style" class="level1">
<h1>Do It With Style</h1>
<p>This all may be nice and good, but what if you don’t like the style the programmer gave the tables? What if you need a different style? Change everything by hand afterwards? Not at all, you can just create your own style as simple as this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Want a blue header color? Sure.</span></span>
<span id="cb8-2">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">excel_output_style</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header_back_color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0000FF"</span>)</span>
<span id="cb8-3"></span>
<span id="cb8-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># But with red font color? No problem.</span></span>
<span id="cb8-5">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_style <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_output_style</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header_font_color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FF0000"</span>)</span>
<span id="cb8-6"></span>
<span id="cb8-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Another font and individual column width? Why not.</span></span>
<span id="cb8-8">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_style <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_output_style</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font         =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Times New Roman"</span>,</span>
<span id="cb8-9">                                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">column_width =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>))</span>
<span id="cb8-10"></span>
<span id="cb8-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Change the font size for the titles and remove borders around the row header? Absolutely.</span></span>
<span id="cb8-12">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_style <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_output_style</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title_font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>,</span>
<span id="cb8-13">                                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cat_col_borders =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb8-14">                                            </span>
<span id="cb8-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Now let's integrate this new style</span></span>
<span id="cb8-16">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + age"</span>),</span>
<span id="cb8-17">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,</span>
<span id="cb8-18">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by         =</span> state,</span>
<span id="cb8-19">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb8-20">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"freq"</span>),</span>
<span id="cb8-21">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_group  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>,</span>
<span id="cb8-22">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex   =</span> sex.,</span>
<span id="cb8-23">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age   =</span> age.,</span>
<span id="cb8-24">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state =</span> state.),</span>
<span id="cb8-25">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style      =</span> my_style,</span>
<span id="cb8-26">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb8-27">                     </span>
<span id="cb8-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Done.</span></span></code></pre></div></div>
</div>
<p>As I said: It doesn’t get more complex. You can add many more things to your tables just as easy. No complex programming needed, just a little bit of imagination. For more examples see the reference.</p>
<p>And now go and create some good looking tables!</p>
<p><img src="https://your-website-url.example.com/posts/02. SAS compare/tabulation.png" class="img-fluid"></p>


</section>

 ]]></description>
  <category>R</category>
  <category>Showcase</category>
  <guid>https://your-website-url.example.com/posts/02. SAS compare/</guid>
  <pubDate>Fri, 31 Oct 2025 23:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/02. SAS compare/logo.png" medium="image" type="image/png" height="47" width="144"/>
</item>
<item>
  <title>Bringing Powerful ‘SAS’ Inspired Concepts for more Efficient Bigger Outputs to ‘R’</title>
  <dc:creator>qol Blog</dc:creator>
  <link>https://your-website-url.example.com/posts/01. Initial post/</link>
  <description><![CDATA[ 






<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/01. Initial post/logo.png" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:25.0%"></p>
</figure>
</div>
<p>The main goal is to make descriptive evaluations easier to create bigger and more complex outputs in less time with less code. Introducing format containers with multilabels, a more powerful summarise which is capable to output every possible combination of the provided grouping variables in one go, tabulation functions which can create any table in different styles and other more readable functions. The code is optimized to work fast even with datasets of over a million observations.</p>
<section id="installation" class="level2">
<h2 class="anchored" data-anchor-id="installation">Installation</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Official release</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qol"</span>)</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Development version</span></span>
<span id="cb1-5">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s3rdia/qol"</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'qol'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">repos =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://s3rdia.r-universe.dev'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://cloud.r-project.org'</span>))</span>
<span id="cb1-8"></span>
<span id="cb1-9">pak<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pak</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s3rdia/qol"</span>)</span></code></pre></div></div>
</div>
</section>
<section id="format-containers" class="level2">
<h2 class="anchored" data-anchor-id="format-containers">Format Containers</h2>
<p>Create a format container independent from any data frame. Define which values should be recoded into which new categories, if the format is applied to a variable in a data frame. It is possible to assign a single value to multiple new categories to create a multilabel. With these format containers, you just keep a small reference of original values and result categories. Formats and data find their way together only just before computing the results. This method is very memory efficient, readable and user friendly for creating larger and more complex outputs at the same time.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Creating format containers</span></span>
<span id="cb2-2">age. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb2-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb2-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb2-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb2-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb2-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb2-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb2-9"></span>
<span id="cb2-10">sex. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb2-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb2-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb2-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
</div>
</section>
<section id="massive-outputs-simple-and-fast" class="level2">
<h2 class="anchored" data-anchor-id="massive-outputs-simple-and-fast">Massive Outputs: Simple and fast</h2>
<p>The package builds on the incredibly fast <a href="https://github.com/fastverse/collapse">collapse</a> and <a href="https://github.com/Rdatatable/data.table">data.table</a> packages. In addition the code is optimized to handle big datasets efficiently with the format concept.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(qol)</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If you want to test the raw speed in combination with creating big outputs try this:</span></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Lets crank up the observations to 10 Millions</span></span>
<span id="cb3-5">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000000</span>)</span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create format containers</span></span>
<span id="cb3-8">age. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb3-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb3-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb3-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb3-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb3-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb3-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb3-15"></span>
<span id="cb3-16">sex. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb3-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb3-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb3-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb3-20"></span>
<span id="cb3-21">education. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb3-22">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>            <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>),</span>
<span id="cb3-23">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low education"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>,</span>
<span id="cb3-24">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle education"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>,</span>
<span id="cb3-25">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high education"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)</span>
<span id="cb3-26">    </span>
<span id="cb3-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># And now let's take a second and see what massive outputs we can get in no time</span></span>
<span id="cb3-28">summary_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-29">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class      =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, sex, age, education),</span>
<span id="cb3-30">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(income, probability, weight),</span>
<span id="cb3-31">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"freq"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum_wgt"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_total"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"missing"</span>),</span>
<span id="cb3-32">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.,</span>
<span id="cb3-33">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex.,</span>
<span id="cb3-34">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.),</span>
<span id="cb3-35">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"weight"</span>,</span>
<span id="cb3-36">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nesting    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>,</span>
<span id="cb3-37">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">notes      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</div>
<p><img src="https://your-website-url.example.com/posts/01. Initial post/output.png" class="img-fluid"></p>
<p>The operations based on summarisation are the fastest. Other operations take a bit longer but still work fast with big datasets.</p>
</section>
<section id="powerful-tabulation" class="level2">
<h2 class="anchored" data-anchor-id="powerful-tabulation">Powerful tabulation</h2>
<p>Using the wonderful <a href="https://github.com/JanMarvin/openxlsx2">openxlsx2</a> package for maximum style, you can basically output any table fully styled with little effort. Combine any number of variables in any possible way, all at once. Setting up a custom, reusable style is as easy as setting up options like: provide a color for the table header, set the font size for the row header, should borders be drawn for the table cells yes/no, and so on. You can fully concentrate on designing a table, instead of thinking hard about how to calculate where to put a border or to even manually prepare a designed workbook.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100000</span>)</span>
<span id="cb4-2"></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create format containers</span></span>
<span id="cb4-4">age. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb4-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>          <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb4-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,</span>
<span id="cb4-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 25"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>,</span>
<span id="cb4-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to under 55"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54</span>,</span>
<span id="cb4-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to under 65"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">64</span>,</span>
<span id="cb4-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb4-11"></span>
<span id="cb4-12">sex. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb4-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb4-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-15">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb4-16"></span>
<span id="cb4-17">education. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb4-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>            <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>),</span>
<span id="cb4-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low education"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>,</span>
<span id="cb4-20">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle education"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>,</span>
<span id="cb4-21">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high education"</span>   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)</span>
<span id="cb4-22">    </span>
<span id="cb4-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define style</span></span>
<span id="cb4-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">column_widths =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>))</span>
<span id="cb4-25"></span>
<span id="cb4-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define titles and footnotes. If you want to add hyperlinks you can do so by</span></span>
<span id="cb4-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># adding "link:" followed by the hyperlink to the main text.</span></span>
<span id="cb4-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_titles</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is title number 1 link: https://cran.r-project.org/"</span>,</span>
<span id="cb4-29">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is title number 2"</span>,</span>
<span id="cb4-30">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is title number 3"</span>)</span>
<span id="cb4-31"></span>
<span id="cb4-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_footnotes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is footnote number 1"</span>,</span>
<span id="cb4-33">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is footnote number 2"</span>,</span>
<span id="cb4-34">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This is footnote number 3 link: https://cran.r-project.org/"</span>)</span>
<span id="cb4-35"></span>
<span id="cb4-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Output complex tables with different percentages</span></span>
<span id="cb4-37">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>),</span>
<span id="cb4-38">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education + year"</span>),</span>
<span id="cb4-39">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb4-40">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>),</span>
<span id="cb4-41">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_group  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>),</span>
<span id="cb4-42">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.,</span>
<span id="cb4-43">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.),</span>
<span id="cb4-44">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb4-45"></span>
<span id="cb4-46"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reset_style_options</span>()</span>
<span id="cb4-47"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reset_qol_options</span>()</span></code></pre></div></div>
</div>
<p><img src="https://your-website-url.example.com/posts/01. Initial post/tabulation.png" class="img-fluid"></p>
<p>You can also combine multiple tables in one workbook, each on a different sheet, and save the file, instead of just viewing it.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set output and style options globally</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">save_path  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:/My_folder/"</span>,</span>
<span id="cb5-3">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file       =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"My_workbook.xlsx"</span>,</span>
<span id="cb5-4">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age_sex"</span>)</span>
<span id="cb5-5"></span>
<span id="cb5-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Capture the output of any_table() to get a list which contains the data frame</span></span>
<span id="cb5-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># as well as the formatted workbook.</span></span>
<span id="cb5-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Note: Set print to FALSE to prevent the workbook from being saved to early.</span></span>
<span id="cb5-9">result_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-10">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>),</span>
<span id="cb5-11">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>),</span>
<span id="cb5-12">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb5-13">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>),</span>
<span id="cb5-14">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb5-15">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb5-16">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb5-17"></span>
<span id="cb5-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set a new sheet name for the next table</span></span>
<span id="cb5-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"edu_year"</span>)</span>
<span id="cb5-20"></span>
<span id="cb5-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pass on the workbook from before to the next any_table()</span></span>
<span id="cb5-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print is now TRUE so the workbook will be saved.</span></span>
<span id="cb5-23">my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workbook   =</span> result_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"workbook"</span>]],</span>
<span id="cb5-24">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education"</span>),</span>
<span id="cb5-25">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>),</span>
<span id="cb5-26">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb5-27">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_group"</span>),</span>
<span id="cb5-28">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.),</span>
<span id="cb5-29">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb5-30">                     </span>
<span id="cb5-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For safety set file back to NULL at the end. Otherwise the next any_table() will overwrite</span></span>
<span id="cb5-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the existing file.</span></span>
<span id="cb5-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">close_file</span>()</span></code></pre></div></div>
</div>
<p>In case you have a good amount of tables, you want to combine in a single workbook, you can also catch the outputs and combine them afterwards in one go:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set output and style options globally</span></span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age_sex"</span>)</span>
<span id="cb6-3"></span>
<span id="cb6-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Catch the output as shown before, but additionally use the option -&gt; output = "excel_nostyle".</span></span>
<span id="cb6-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This skips the styling part, so that the function runs faster. The styling is done later on.</span></span>
<span id="cb6-6">tab1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rows       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>),</span>
<span id="cb6-8">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>),</span>
<span id="cb6-9">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values     =</span> weight,</span>
<span id="cb6-10">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>),</span>
<span id="cb6-11">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb6-12">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb6-13">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb6-14">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel_nostyle"</span>)</span>
<span id="cb6-15"></span>
<span id="cb6-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Now let's asume you create a bunch of different tables</span></span>
<span id="cb6-17">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_style <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sheet2"</span>)</span>
<span id="cb6-18">tab2     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(..., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel_nostyle"</span>)</span>
<span id="cb6-19"></span>
<span id="cb6-20">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_style <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sheet3"</span>)</span>
<span id="cb6-21">tab3     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(..., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel_nostyle"</span>)</span>
<span id="cb6-22"></span>
<span id="cb6-23">my_style <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_style <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_style_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sheet4"</span>)</span>
<span id="cb6-24">tab4     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any_table</span>(..., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"excel_nostyle"</span>)</span>
<span id="cb6-25"></span>
<span id="cb6-26">...</span>
<span id="cb6-27"></span>
<span id="cb6-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Every of the above tabs is a list, which contains the data table, an unstyled workbook and the meta</span></span>
<span id="cb6-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># information needed for the individual styling. These tabs can be input into the following function,</span></span>
<span id="cb6-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># which reads the meta information, styles each table individually and combines them as separate sheets</span></span>
<span id="cb6-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># into a single workbook.</span></span>
<span id="cb6-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">combine_into_workbook</span>(tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8,</span>
<span id="cb6-33">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C:/My_folder/My_workbook.xlsx"</span>)</span></code></pre></div></div>
</div>
</section>
<section id="one-function-to-join-them-all" class="level2">
<h2 class="anchored" data-anchor-id="one-function-to-join-them-all">One Function to Join Them All</h2>
<p>Join two or more data frames together in one operation with multiple different join methods and join on differently named variables. Available methods are: left, right, inner, full, outer, left_inner, right_inner.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simple join</span></span>
<span id="cb7-2">df1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb7-3">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a   =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>))</span>
<span id="cb7-4"></span>
<span id="cb7-5">df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb7-6">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b   =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>))</span>
<span id="cb7-7"></span>
<span id="cb7-8">left_joined <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">multi_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(df1, df2), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">on =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"key"</span>)</span>
<span id="cb7-9"></span>
<span id="cb7-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Joining more than two data frames on different variable names with different methods</span></span>
<span id="cb7-11">df1b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb7-12">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>),</span>
<span id="cb7-13">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>))</span>
<span id="cb7-14"></span>
<span id="cb7-15">df2b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb7-16">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>),</span>
<span id="cb7-17">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>))</span>
<span id="cb7-18"></span>
<span id="cb7-19">df3b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">any  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb7-20">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>),</span>
<span id="cb7-21">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>))</span>
<span id="cb7-22"></span>
<span id="cb7-23">multiple_joined3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">multi_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(df1b, df2b, df3b),</span>
<span id="cb7-24">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">on =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df1b =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"key1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"key2"</span>),</span>
<span id="cb7-25">                                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df2b =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var2"</span>),</span>
<span id="cb7-26">                                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df3b =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"any"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>)),</span>
<span id="cb7-27">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">how =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>))</span></code></pre></div></div>
</div>
</section>
<section id="transpose-like-never-before" class="level2">
<h2 class="anchored" data-anchor-id="transpose-like-never-before">Transpose like never before</h2>
<p>Transpose, weight results and generate additional categories all in one operation. Put variables side by side or nest them or both, just as you need it. And of course you can transpose multiple variables from wide into long format in one go.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Transpose from long to wide and use a multilabel to generate additional categories</span></span>
<span id="cb8-2">long_to_wide <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, age),</span>
<span id="cb8-4">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex + education"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"education"</span>),</span>
<span id="cb8-5">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values   =</span> income,</span>
<span id="cb8-6">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> sex., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> age.),</span>
<span id="cb8-7">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight   =</span> weight,</span>
<span id="cb8-8">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm    =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb8-9"></span>
<span id="cb8-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Transpose back from wide to long</span></span>
<span id="cb8-11">wide_to_long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long_to_wide <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(year, age),</span>
<span id="cb8-13">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pivot    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span>),</span>
<span id="cb8-14">                                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)))</span></code></pre></div></div>
</div>
</section>
<section id="sorting-with-additions" class="level2">
<h2 class="anchored" data-anchor-id="sorting-with-additions">Sorting with additions</h2>
<p>Sort cases while preserving the order of certain variables or make use of formats to sort in format order, which can be used to e.g.&nbsp;sort a character variable in another than alphabetical order without creating a temporary variable just for sorting.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">education. <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">discrete_format</span>(</span>
<span id="cb9-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low"</span>,</span>
<span id="cb9-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>,</span>
<span id="cb9-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)</span>
<span id="cb9-5"></span>
<span id="cb9-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simple sorting</span></span>
<span id="cb9-7">sort_df1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(state, sex, age))</span>
<span id="cb9-8">sort_df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(state, sex, age),</span>
<span id="cb9-9">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ascending"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"descending"</span>))</span>
<span id="cb9-10"></span>
<span id="cb9-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Character variables will normally be sorted alphabetically. With the help</span></span>
<span id="cb9-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># of a format this variable can be sorted in a completely different way.</span></span>
<span id="cb9-13">sort_df3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by      =</span> education,</span>
<span id="cb9-14">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">education =</span> education.))</span>
<span id="cb9-15"></span>
<span id="cb9-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Preserve the order of the character variable, otherwise it couldn't stay in</span></span>
<span id="cb9-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># it's current order.</span></span>
<span id="cb9-18">sort_df4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sort_df3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort_plus</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by       =</span> age,</span>
<span id="cb9-19">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">preserve =</span> education)</span></code></pre></div></div>
</div>
</section>
<section id="readability" class="level2">
<h2 class="anchored" data-anchor-id="readability">Readability</h2>
<p>There are also some functions which enhance the readability of the code. For example if - else if - else statements like in other languages:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example data frame</span></span>
<span id="cb10-2">my_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dummy_data</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb10-3"></span>
<span id="cb10-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Call function</span></span>
<span id="cb10-5">new_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-6">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>,             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_group =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_if.</span>(age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_group =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 65"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>   (                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_group =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>)</span>
<span id="cb10-9"></span>
<span id="cb10-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Or with multiple variables</span></span>
<span id="cb10-11">new_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-12">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>,             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_group =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under 18"</span>      , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_num =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_if.</span>(age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">65</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_group =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to under 65"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_num =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>L) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>   (                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_group =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 and older"</span>,   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_num =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L)</span>
<span id="cb10-15"></span>
<span id="cb10-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">NOTE</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">: As in other languages the following if blocks won't produce the same result.</span></span>
<span id="cb10-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#       if.() will overwrite existing values while else_if.() will not.</span></span>
<span id="cb10-18">state_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-19">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(state <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state_a =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"State 1"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_if.</span>(state <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state_a =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>   (            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state_a =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"East"</span>)</span>
<span id="cb10-22"></span>
<span id="cb10-23">state_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> state_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-24">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(state <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state_b =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"State 1"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(state <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state_b =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>(            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state_b =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"East"</span>)</span>
<span id="cb10-27">    </span>
<span id="cb10-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use if.() as a do-over-loop. In this kind of loop all vectors will be</span></span>
<span id="cb10-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># advanced one iteration at a time in parallel.</span></span>
<span id="cb10-30">money    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"income"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"expenses"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"balance"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"probability"</span>)</span>
<span id="cb10-31">new_vars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var3"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var4"</span>)</span>
<span id="cb10-32">result   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb10-33"></span>
<span id="cb10-34">do_over_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-35">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(money <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_vars =</span> result) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>(           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_vars =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb10-37">    </span>
<span id="cb10-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># All these functions can be used in a do_if() situation and are aware of</span></span>
<span id="cb10-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># overarching conditions.</span></span>
<span id="cb10-40">do_if_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-41">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do_if</span>(state <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-42">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_cat =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-43">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>(          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_cat =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-44">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else_do</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-45">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if.</span>(age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_cat =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-46">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">else.</span>(          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_cat =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-47">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">end_do</span>()</span></code></pre></div></div>
</div>
</section>
<section id="monitoring" class="level2">
<h2 class="anchored" data-anchor-id="monitoring">Monitoring</h2>
<p>This package also includes some basic yet very effective performance monitoring functions. The heavier functions in this package already make use of them and can show how they work internally like this:</p>
<p><img src="https://your-website-url.example.com/posts/01. Initial post/monitor.png" class="img-fluid"></p>
</section>
<section id="customizing-visual-appearance" class="level2">
<h2 class="anchored" data-anchor-id="customizing-visual-appearance">Customizing Visual Appearance</h2>
<p>Don’t like the colors of the built-in in RStudio themes? Can’t find a theme online that fits your liking? No Problem. With a simple function you can create a full theme file and decide which parts of the editor receive which colors. The themes shown below and the corresponding code can be found on GitHub.</p>
<p><img src="https://your-website-url.example.com/posts/01. Initial post/theme.png" class="img-fluid"></p>


</section>

 ]]></description>
  <category>R</category>
  <category>Showcase</category>
  <guid>https://your-website-url.example.com/posts/01. Initial post/</guid>
  <pubDate>Thu, 09 Oct 2025 22:00:00 GMT</pubDate>
  <media:content url="https://your-website-url.example.com/posts/01. Initial post/logo.png" medium="image" type="image/png" height="167" width="144"/>
</item>
</channel>
</rss>
