<?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: Help with merging and duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461375#M117364</link>
    <description>&lt;P&gt;Hi:&lt;BR /&gt;&amp;nbsp; Just a note about using MONOTONIC -- there have been previous postings about this -- there's a Tech Support note &lt;A href="http://support.sas.com/techsup/notes/v8/15/138.html" target="_blank"&gt;http://support.sas.com/techsup/notes/v8/15/138.html&lt;/A&gt; that says:&lt;BR /&gt;"&lt;STRONG&gt;The MONOTONIC() function is not supported in PROC SQL.&amp;nbsp; Using the MONOTONIC() function in PROC SQL can cause missing or non-sequential values to be returned."&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; This might make the suggestion produce unreliable results.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
    <pubDate>Thu, 10 May 2018 18:03:49 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2018-05-10T18:03:49Z</dc:date>
    <item>
      <title>Help with merging and duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461350#M117351</link>
      <description>&lt;P&gt;How do I add my flags to my table1 id's? Without adding or subtracting from my existing table1 id's?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 3 tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table1 has thousands of id's, some are duplicate and I need to keep them all (even the dups). On my other table I have many more id's and a 1 or 0 flag, same for the third table but it is a different flag (but still 1 or 0).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit: table2 and table3 have several duplicates...so if a record has a 1 flag (or several) then on my join table I'd like them to have a 1 flag. But if the there several duplicates and they all have a 0 flag and no 1 flag then my new table should also have a 0 flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to add another 2&amp;nbsp;columns to table1 where I keep all the original id's (even the dups) and the new column contains the flags for other two tables by id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my problem is when I use this code, it adds more dups, but if I use distinct then I drop the dups that I do need (the ones from table1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table join as 
select a.ed_id, score1, score2
from table1 a
left join table2 b
on a.ed_id= b.ed_id
left join table3 c
on a.ed_id= c.ed_id
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 15:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461350#M117351</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-05-10T15:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging and duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461356#M117353</link>
      <description>&lt;P&gt;The simplest I can think of is probably this using proc sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;drop table table1;&lt;BR /&gt;create table table1(&lt;BR /&gt;edid char(20)&lt;BR /&gt;);&lt;BR /&gt;insert into table1&lt;BR /&gt;values ('dup1')&lt;BR /&gt;values ('dup2')&lt;BR /&gt;values ('dup1')&lt;BR /&gt;values ('dup1')&lt;BR /&gt;values ('dup3')&lt;BR /&gt;;&lt;BR /&gt;create table table1 as&lt;BR /&gt;select *, monotonic() as row&lt;BR /&gt;from table1&lt;BR /&gt;order by edid;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql; create table test as&lt;BR /&gt;select a.edid, a.row&lt;BR /&gt;,case when a.row = b.m_row then 1 else 0 end as dup_flag&lt;BR /&gt;from table1 a&lt;BR /&gt;left join (select distinct edid, min(row) as m_row from table1) b&lt;BR /&gt;on a.edid = b.edid&lt;BR /&gt;order by a.edid&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 15:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461356#M117353</guid>
      <dc:creator>Larrihoover</dc:creator>
      <dc:date>2018-05-10T15:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging and duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461358#M117355</link>
      <description>&lt;P&gt;Show some example input data for each data set and the desired final output. Best is if each of the sets is presented as data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 15:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461358#M117355</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-10T15:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging and duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461375#M117364</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;&amp;nbsp; Just a note about using MONOTONIC -- there have been previous postings about this -- there's a Tech Support note &lt;A href="http://support.sas.com/techsup/notes/v8/15/138.html" target="_blank"&gt;http://support.sas.com/techsup/notes/v8/15/138.html&lt;/A&gt; that says:&lt;BR /&gt;"&lt;STRONG&gt;The MONOTONIC() function is not supported in PROC SQL.&amp;nbsp; Using the MONOTONIC() function in PROC SQL can cause missing or non-sequential values to be returned."&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; This might make the suggestion produce unreliable results.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 18:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461375#M117364</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-05-10T18:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging and duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461411#M117376</link>
      <description>&lt;P&gt;This will fix flags for table 1. From reading your question again, I am not sure for table 2 and 3 how the data will join without seeing it or if I am understanding the question correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;drop table main;&lt;BR /&gt;create table main(&lt;BR /&gt;edid char(20)&lt;BR /&gt;);&lt;BR /&gt;insert into main&lt;BR /&gt;values ('dup1')&lt;BR /&gt;values ('dup2')&lt;BR /&gt;values ('dup1')&lt;BR /&gt;values ('dup1')&lt;BR /&gt;values ('dup3')&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;proc sort data=main; by edid; run;&lt;/P&gt;&lt;P&gt;data table1;&lt;BR /&gt;set main;&lt;BR /&gt;count + 1;&lt;BR /&gt;by edid;&lt;BR /&gt;if first.edid then do;&lt;BR /&gt;count = 1;&lt;BR /&gt;flag_t1=1;&lt;BR /&gt;end;&lt;BR /&gt;else flag_t1 = 0;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 20:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-merging-and-duplicates/m-p/461411#M117376</guid>
      <dc:creator>Larrihoover</dc:creator>
      <dc:date>2018-05-10T20:06:40Z</dc:date>
    </item>
  </channel>
</rss>

