<?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: how/where to use calculated column in proc sql union in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673054#M202391</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    sum(gross_cam_t0) as gross_cam_t0 ,
    sum(gross_cam_t1) as gross_cam_t1,
    (select sum(delta) from have2) as delta,
    calculated gross_cam_t0 + calculated delta - calculated gross_cam_t1 as check_ugual_zero
  from have_1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jul 2020 08:26:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-07-29T08:26:42Z</dc:date>
    <item>
      <title>how/where to use calculated column in proc sql union</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673044#M202385</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I am trying to write a proc sql to compute a check variabile that should be ugual to zero, but SAS return to me this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: It appears that the CALCULATED variable gross_cam_t0 was referenced before it was defined.&lt;/P&gt;&lt;P&gt;ERROR: It appears that the CALCULATED variable gross_cam_t1 was referenced before it was defined.&lt;/P&gt;&lt;P&gt;ERROR: The following columns were not found as CALCULATED references in the immediate query: gross_cam_t0, gross_cam_t1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are my two input dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_1;
    input id $2. gross_cam_t0 gross_cam_t1;
datalines;
A1 10 5
B2 1 1
C3 8 11
;
run;

data have_2;&lt;BR /&gt;    input delta;
datalines;
-5
0
3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I would like to have&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
     input gross_cam_t0_tot gross_cam_t1_tot delta_tot;
datalines;
19 17 -2
;
run;

data want;
    set temp;
    check_ugual_zero = sum(gross_cam_t0_tot,delta_tot,-gross_cam_t1_tot);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is my SAS code that dosen't work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select   sum(gross_cam_t0) as gross_cam_t0 ,
              sum(gross_cam_t1) as gross_cam_t1
     from have_1 outer union corr
        select sum(delta) as delta,
               calculated gross_cam_t0 + calculated delta - calculated gross_cam_t1 as check_ugual_zero
        from have_2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I am not clear pleas write me and I'll give more detail.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Plese help me to fix this code. Thanks a lot!&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 06:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673044#M202385</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-07-29T06:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: how/where to use calculated column in proc sql union</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673054#M202391</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    sum(gross_cam_t0) as gross_cam_t0 ,
    sum(gross_cam_t1) as gross_cam_t1,
    (select sum(delta) from have2) as delta,
    calculated gross_cam_t0 + calculated delta - calculated gross_cam_t1 as check_ugual_zero
  from have_1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 08:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673054#M202391</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-29T08:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: how/where to use calculated column in proc sql union</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673131#M202437</link>
      <description>&lt;P&gt;Great! thanks for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 13:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-where-to-use-calculated-column-in-proc-sql-union/m-p/673131#M202437</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-07-29T13:56:29Z</dc:date>
    </item>
  </channel>
</rss>

