<?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: Writing conditions in Proc Sql based on user defined variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162650#M42254</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As LinusH mentioned there is calculated.&amp;nbsp; However you can also do these things by subquerying.&amp;nbsp; There are times when each method is useful, depending on the complexity of the SQL being created.&amp;nbsp; The below is logically the same, the first using a value which is calculated within the same select, the second having that value created as part of the select in the subquery.&amp;nbsp; In this simple example it may look a bit pointless, however if you are writing large queries which utilize many datasets, calculations, grouping etc. (say something like and ADSL table) then it can be useful to pre-process data going into your query to simplify things.&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table ... as&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; values,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when else,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case calculated when else&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; a_dataset;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table ... as &lt;BR /&gt;&amp;nbsp; select&amp;nbsp; values,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when calculated else&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; (select values,&lt;BR /&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when else as calculated&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp; a_dateset);&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Apr 2014 12:34:42 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-04-01T12:34:42Z</dc:date>
    <item>
      <title>Writing conditions in Proc Sql based on user defined variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162648#M42252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose I've got a code like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table DATASET1 as select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when a.VAR1 + a.VAR2 &amp;gt; 3 then 'UVAR1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end as MYVAR1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when a.VAR1 + a.VAR3 = 0 then 'UVAR2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end as MYVAR2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from DATASET;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to add an extra 'case when', but instead of using variables from DATASET I would like to use my variables MYVAR1 and MYVAR2. Is there a way to do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2014 11:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162648#M42252</guid>
      <dc:creator>Lupacante</dc:creator>
      <dc:date>2014-04-01T11:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Writing conditions in Proc Sql based on user defined variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162649#M42253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, there is.&lt;/P&gt;&lt;P&gt;Use the keyword &lt;EM&gt;Calculated&lt;/EM&gt;, which an extremely useful SAS extension to ANSI SQL. It's more cumbersome to solve this in other SQL dialects.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2014 11:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162649#M42253</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-04-01T11:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Writing conditions in Proc Sql based on user defined variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162650#M42254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As LinusH mentioned there is calculated.&amp;nbsp; However you can also do these things by subquerying.&amp;nbsp; There are times when each method is useful, depending on the complexity of the SQL being created.&amp;nbsp; The below is logically the same, the first using a value which is calculated within the same select, the second having that value created as part of the select in the subquery.&amp;nbsp; In this simple example it may look a bit pointless, however if you are writing large queries which utilize many datasets, calculations, grouping etc. (say something like and ADSL table) then it can be useful to pre-process data going into your query to simplify things.&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table ... as&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; values,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when else,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case calculated when else&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; a_dataset;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table ... as &lt;BR /&gt;&amp;nbsp; select&amp;nbsp; values,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when calculated else&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; (select values,&lt;BR /&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when else as calculated&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp; a_dateset);&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2014 12:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Writing-conditions-in-Proc-Sql-based-on-user-defined-variables/m-p/162650#M42254</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-04-01T12:34:42Z</dc:date>
    </item>
  </channel>
</rss>

