<?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 How to not get duplicate results. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448393#M112780</link>
    <description>&lt;P&gt;I have a spreadsheet attached below of 2 tables that I am trying to join. but I"m having trouble with getting duplicate results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to join left join T2 to T1 (join by "ID"), and return a table that looks like T3....but without the duplicate "costs".&amp;nbsp; I only want "Cost" to be returned once per ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the statement below, but&amp;nbsp; it actually wont work for me because during the query process, there's other tables involved and the final result might not include 'Phone 1'.&amp;nbsp; I really just need the cost to be returned once to any row that is available&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(Case when phone &amp;gt; 1 then 0 else Cost end)&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;another option is to use the row_over and&amp;nbsp;partition function, but I'm wondering if there is an easier/simpler logic that I can use instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to stay in proc sql if possible&lt;/P&gt;</description>
    <pubDate>Sat, 24 Mar 2018 04:25:01 GMT</pubDate>
    <dc:creator>mrdlau</dc:creator>
    <dc:date>2018-03-24T04:25:01Z</dc:date>
    <item>
      <title>How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448393#M112780</link>
      <description>&lt;P&gt;I have a spreadsheet attached below of 2 tables that I am trying to join. but I"m having trouble with getting duplicate results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to join left join T2 to T1 (join by "ID"), and return a table that looks like T3....but without the duplicate "costs".&amp;nbsp; I only want "Cost" to be returned once per ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the statement below, but&amp;nbsp; it actually wont work for me because during the query process, there's other tables involved and the final result might not include 'Phone 1'.&amp;nbsp; I really just need the cost to be returned once to any row that is available&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(Case when phone &amp;gt; 1 then 0 else Cost end)&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;another option is to use the row_over and&amp;nbsp;partition function, but I'm wondering if there is an easier/simpler logic that I can use instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to stay in proc sql if possible&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 04:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448393#M112780</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-03-24T04:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448394#M112781</link>
      <description>&lt;P&gt;So T3 is not what you want. What do you want that't not in T2?&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 04:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448394#M112781</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-24T04:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448395#M112782</link>
      <description>&lt;P&gt;Couldn't you use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;           case
             when phones gt min(phones) 0
             else cost&lt;BR /&gt;           end&lt;BR /&gt;         group by id&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 04:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448395#M112782</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-24T04:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448397#M112783</link>
      <description>&lt;P&gt;My columns in T3 should have Phone, ID, and cost....but I only want cost to appear once for each ID.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 05:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448397#M112783</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-03-24T05:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448398#M112784</link>
      <description>&lt;P&gt;I would try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table T3 as
select
    a.ID,
    a.Phones,
    t2.cost
from 
    (select ID, max(Phones) as Phones from T1 group by ID) as a left join 
    T2 on a.ID = T2.ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 05:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448398#M112784</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-24T05:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448424#M112791</link>
      <description>&lt;P&gt;I think you are looking for:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table t3 as
    select a.ID,a.Phones,
           case
             when phones gt min(phones) then 0
             else b.cost
           end as Cost
      from t1 a left join t2 b
        on a.ID=b.ID
          group by a.ID
            order by a.ID,a.Phones
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 14:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448424#M112791</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-24T14:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448449#M112809</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; This works for me.....but now that I apply that to my code, I'm wondering if I can use data step just for that section.&amp;nbsp; My query is long and if I use min/max in my proc sql;, I need to do a huge group by.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;that's fine, but I think a separate data step just to remove the duplicates might be a bit cleaner.&amp;nbsp; Is it possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what I had, but I have, but it's not working because it's evaluating it row by row, rather than each group.&amp;nbsp; I,e&amp;nbsp;I'm getting the actual cost on each row&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.T3;
SET WORK.T3;
IF Phones &amp;gt; MIN(phones) THEN cost 0; ELSE cost = cost;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I even tried adding a "by ID" but it didn't work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 20:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448449#M112809</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-03-24T20:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to not get duplicate results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448452#M112810</link>
      <description>&lt;P&gt;If your current table3 has the first record for each ID having the lowest phone value, then I'd use a data step, using ID as the by variable, and use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;IF not first.ID THEN cost=0;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 20:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-not-get-duplicate-results/m-p/448452#M112810</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-24T20:31:27Z</dc:date>
    </item>
  </channel>
</rss>

