<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Best practice or short cut on multiple SQL CASE statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-practice-or-short-cut-on-multiple-SQL-CASE-statements/m-p/453356#M284024</link>
    <description>&lt;P&gt;Store your data in a long format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the calculation once&lt;/P&gt;
&lt;P&gt;Use TRANSPOSE/REPORT to flip your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do it in a data step in an array for the calculations. That's likely the easiest/quickest fix.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Apr 2018 20:12:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-04-11T20:12:09Z</dc:date>
    <item>
      <title>Best practice or short cut on multiple SQL CASE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-practice-or-short-cut-on-multiple-SQL-CASE-statements/m-p/453350#M284023</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm writing a query involving multiple left joins using several months' worth of data for same group of customers.&lt;/P&gt;&lt;P&gt;To help end user understand arbitrary value, I add a CASE statement to include the Value description.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone suggest a way for me to only have to write the case description ONCE, so then each subsequent month/ and case the&amp;nbsp; value need not be re written? Should this be done via MACRO, and then referring to it using the INCLUDE statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;End result would look like:&lt;/P&gt;&lt;P&gt;Acct&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Status_mon01&amp;nbsp; &amp;nbsp;Desc_mon01&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Status_mon02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Desc_mon02&amp;nbsp; &amp;nbsp;/*and so on */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; No mail&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; No Mail&lt;/P&gt;&lt;P&gt;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vacation&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pending&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample code:&lt;/P&gt;&lt;P&gt;proc sql; create table base&amp;nbsp;&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;t1.*,&lt;/P&gt;&lt;P&gt;t2.&lt;SPAN&gt;Status as&amp;nbsp;Status_mon01,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;case&amp;nbsp; t2.status&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;when 'A' then 'MAIL'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;when 'S' then 'No mail'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/* and so one until end of when-then */ &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end as Desc_mon01,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;t3.status as status_mon02,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;case &amp;lt;...&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;from table1 as t1 left join &amp;lt;...&amp;gt; on &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;t1.id=t2.id &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;left join &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;lt;...&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank you&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 19:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-practice-or-short-cut-on-multiple-SQL-CASE-statements/m-p/453350#M284023</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2018-04-11T19:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Best practice or short cut on multiple SQL CASE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-practice-or-short-cut-on-multiple-SQL-CASE-statements/m-p/453356#M284024</link>
      <description>&lt;P&gt;Store your data in a long format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the calculation once&lt;/P&gt;
&lt;P&gt;Use TRANSPOSE/REPORT to flip your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do it in a data step in an array for the calculations. That's likely the easiest/quickest fix.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 20:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-practice-or-short-cut-on-multiple-SQL-CASE-statements/m-p/453356#M284024</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-11T20:12:09Z</dc:date>
    </item>
  </channel>
</rss>

