<?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 problem with union in proc sql for appending two diff data in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/problem-with-union-in-proc-sql-for-appending-two-diff-data/m-p/379316#M3124</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a data where AON is having multiple entries. i fond entries which have MAX(AON) and created a table.&lt;/P&gt;&lt;P&gt;then i wish to append the new and orriginal file but hard luck.&lt;/P&gt;&lt;P&gt;anyhelp guys....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CODE :-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table ans_4B as select* from work.import&lt;BR /&gt;group by PRODUCT_ID&lt;BR /&gt;union&lt;BR /&gt;select PRODUCT_ID , MAX_AON from work.ans_4A;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2017 10:16:40 GMT</pubDate>
    <dc:creator>jonty</dc:creator>
    <dc:date>2017-07-26T10:16:40Z</dc:date>
    <item>
      <title>problem with union in proc sql for appending two diff data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/problem-with-union-in-proc-sql-for-appending-two-diff-data/m-p/379316#M3124</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a data where AON is having multiple entries. i fond entries which have MAX(AON) and created a table.&lt;/P&gt;&lt;P&gt;then i wish to append the new and orriginal file but hard luck.&lt;/P&gt;&lt;P&gt;anyhelp guys....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CODE :-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table ans_4B as select* from work.import&lt;BR /&gt;group by PRODUCT_ID&lt;BR /&gt;union&lt;BR /&gt;select PRODUCT_ID , MAX_AON from work.ans_4A;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 10:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/problem-with-union-in-proc-sql-for-appending-two-diff-data/m-p/379316#M3124</guid>
      <dc:creator>jonty</dc:creator>
      <dc:date>2017-07-26T10:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: problem with union in proc sql for appending two diff data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/problem-with-union-in-proc-sql-for-appending-two-diff-data/m-p/379322#M3126</link>
      <description>&lt;P&gt;Please elaborate on what does not work, provide test data in the form of a datastep in the post (use the {i} to preserve formatting) and what the output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At a guess from the minimal info you provided:&lt;/P&gt;
&lt;P&gt;Union appends one dataset to another asumming that both have the same variables. &amp;nbsp;This is presumably not the case as you select * from the first, and select 2 variables in the second which is unlikely to be the same. &amp;nbsp;Also, you do not group by like, it wouldn't do anything to the data, but is pretty much invalid in that sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want just to add the largest:&lt;/P&gt;
&lt;PRE&gt;proc sort data=imp out=max_imp nodupkey;
  by product_id descending aon;
run;
proc append base=imp data=max_imp force;
run;&lt;/PRE&gt;
&lt;P&gt;Or you could just do it in one datastep, retain the aon each row by product_id and at the end of the group output twice:&lt;/P&gt;
&lt;PRE&gt;data want;
  set imp;
  by product_id;
  retain max_aon;
  if first.product_id then max_aon=aon;
  else if aon &amp;gt; max_aon then max_aon=aon;
  if last.product_id then do;
    output;
    aon=max_aon;
    product_id=cat(product_id," ","Max");
    output;
  end;
  else output;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2017 10:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/problem-with-union-in-proc-sql-for-appending-two-diff-data/m-p/379322#M3126</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-26T10:25:39Z</dc:date>
    </item>
  </channel>
</rss>

