<?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: CALCULATED references in the immediate query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584163#M166316</link>
    <description>&lt;P&gt;I moved the calculated reference variable&amp;nbsp;to front as instructed but still getting the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Aug 2019 11:41:08 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-08-28T11:41:08Z</dc:date>
    <item>
      <title>CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584159#M166313</link>
      <description>&lt;P&gt;I would like to know how to use the variable which was created in proc SQL in the same step for join. Please guide me to resolve this issue. Intention of this step is to complete it in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 11:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584159#M166313</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T11:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584160#M166314</link>
      <description>&lt;P&gt;As it says in &lt;A href="http://support.sas.com/kb/41/911.html" target="_self"&gt;Problem Note&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;41911&lt;/I&gt;&lt;/A&gt;, you can get around this issue by moving the&amp;nbsp;&lt;SPAN&gt;calculated reference to the beginning or to another location, so that it is &lt;STRONG&gt;not&amp;nbsp;&lt;/STRONG&gt;the last reference.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 10:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584160#M166314</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T10:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584163#M166316</link>
      <description>&lt;P&gt;I moved the calculated reference variable&amp;nbsp;to front as instructed but still getting the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 11:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584163#M166316</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T11:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584165#M166317</link>
      <description>&lt;P&gt;Ok, got it. Check out this small example. The first PROC SQL gives an error. The second does not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should give you your answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input ID var1;
datalines;
1 10
2 20
3 30
;

data two;
input ID $ var2;
datalines;
1 10
3 30
;

/* This gives error */
proc sql;
    create table three as
    select one.*, two.var2, cats(one.id) as charID
    from one left join two
    on calculated charID = two.ID;
quit;

/* This does not */
proc sql;
    create table three as
    select one.*, two.var2
    from one left join two
    on cats(one.id) = two.ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either use the CALCULATED keyword in a Having Clause, or do the calculation directly in the On Clause.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 10:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584165#M166317</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T10:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584166#M166318</link>
      <description>&lt;P&gt;I believe you should use the calculated with having in proc sql, so please try this below untested code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   proc sql;
         create table temp3 as
              select cats(substr(put(a.ISSUE_DT,yymmn6.),1,4),"-",substr(put(a.ISSUE_DT,yymmn6.),5)) as
ISSUE_MONTH_INS_CA_FL,a.*,b.INITIAL_DT from INSURANCE_CASHFLOW_updated2  as a left join ADP_OUTPUT_NON_LIFE
as b
                on a.REPORTING_DT=b.REPORTING_DT and
a.ENTITY_ID=b.UNIT
    having calculated ISSUE_MONTH_INS_CA_FL=b.ISSUE_MONTH and a.REPORTING_CAUSE="ACT";

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 10:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584166#M166318</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-27T10:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584209#M166330</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;has given you the answer.&lt;/P&gt;
&lt;P&gt;You cannot use CALCULATED in an ON clause because that is where you are telling SAS how to combine the tables and generate the data records that are used to generate the columns listed between SELECT and FROM.&amp;nbsp; So you cannot use the output to select the input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can either repeat the logic to derive the variable in the ON condition or use a HAVING condition to filter the rows after they have been generated.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584209#M166330</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-27T13:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATED references in the immediate query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584248#M166357</link>
      <description>&lt;P&gt;FWIW , instead of a pretty ugly bit of code:&lt;/P&gt;
&lt;PRE&gt;cats(substr(put(a.ISSUE_DT,yymmn6.),1,4),"-",substr(put(a.ISSUE_DT,yymmn6.),5))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;put(a.ISSUE_DT,yymmd7.)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALCULATED-references-in-the-immediate-query/m-p/584248#M166357</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-27T14:41:22Z</dc:date>
    </item>
  </channel>
</rss>

