<?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: Need help in Merge in Datastep or Join in Proc SQL please in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94781#M9498</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;Please accept my very SINCERE APOLOGIES FOR&amp;nbsp; posting in the incorrect forum. i am not looking to report specially using ODS or anything, i am just simply stuck in getting the ouput right to my code mentioned above. I will make a note not to incorrectly post a discussion next time without fail. SO sorry.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 14 Oct 2012 14:30:01 GMT</pubDate>
    <dc:creator>Andygray</dc:creator>
    <dc:date>2012-10-14T14:30:01Z</dc:date>
    <item>
      <title>Need help in Merge in Datastep or Join in Proc SQL please</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94778#M9495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have 2 datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;EM&gt;Dataset 1 has 150,000 records with the following columns,&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Id , measure1, measure2&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Notes: The dataset 1 has records of many repeats for ids and for all ids, so lot of duplicates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;EM&gt;Dataset2 has 3000 recrods with following columns&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Id, measure3, measure4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Notes: The dataset2 has records with unique ids and no repeats or dupicates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to join or merge the two datasets with the condtion the joined dataset shoud be picked based on the condition measure4 values of dataset2=measure2 values of dataset1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, the final merged dataset shoud only have 3000 records.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 10:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94778#M9495</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2012-10-14T10:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in Merge in Datastep or Join in Proc SQL please</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94779#M9496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I'm not sure that this is really an ODS question, or even a reporting question. Generally, DATA step questions get posted in either the SAS Procedure forum (since you're asking about PROC SQL) or the Macro Facility and DATA step program (since you are asking about a merge).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; However, given what you've posted, I don't know that anyone could provide you much help. You describe the MEASURE4=MEASURE2 condition, but what about ID? Do the ID values have to be part of the matching or joining?&amp;nbsp; How do you want duplicates to be handled -- if there are dups in dataset1 with matches on the MEASURE variables? Do you want to keep duplicates or not? Do you want to take the first, the last, keep all?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; What code have you tried? Have you tried PROC SQL? If so, what was your code? What kind of join condition did you code? Did you try a DATA step program? Did you use IN= options and BY group processing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; My general recommendation for problems of this nature is that you get your logic working on a small subset of data, where you can manually do your matching in order to verify the point at which your program logic will produce the correct results. So, if you have these 2 hypothetical files:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;Data set 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;ID M1 M2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;1&amp;nbsp; 11 22&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;1&amp;nbsp; 12 23&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;2&amp;nbsp; 13 14&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;2&amp;nbsp; 15 16&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;3&amp;nbsp; 17 17&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;3&amp;nbsp; 18 17&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;3&amp;nbsp; 19 14&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;Data set 2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;ID M3 M4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;1&amp;nbsp; 1&amp;nbsp; 17&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;2&amp;nbsp; 2&amp;nbsp; 14&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;3&amp;nbsp; 3&amp;nbsp; 17&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Can you show what results you expect to get? And, what should happen to ID 1, which is in both files, but has no matches on M4=M2.&amp;nbsp; Also, ID=3 has 2 matches for M2=17 -- do you want to keep both of them?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Since you posted your question in the Reporting forum, the next logical question is: what kind of report do you need to produce? How do you plan to report on the results? ODS HTML, ODS RTF, ODS PDF. Were you going to use PROC PRINT, PROC REPORT???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 13:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94779#M9496</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-10-14T13:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in Merge in Datastep or Join in Proc SQL please</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94780#M9497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;after sorting both datasets by id,&lt;/P&gt;&lt;P&gt;i did this step but did not get the desired output&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;merge dataset1(in=a) dataset2 (in=b);&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;if a and b;&lt;/P&gt;&lt;P&gt;where measure4=measure2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 14:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94780#M9497</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2012-10-14T14:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in Merge in Datastep or Join in Proc SQL please</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94781#M9498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;Please accept my very SINCERE APOLOGIES FOR&amp;nbsp; posting in the incorrect forum. i am not looking to report specially using ODS or anything, i am just simply stuck in getting the ouput right to my code mentioned above. I will make a note not to incorrectly post a discussion next time without fail. SO sorry.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 14:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94781#M9498</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2012-10-14T14:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in Merge in Datastep or Join in Proc SQL please</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94782#M9499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If under the same id, there is only ONE measure4=measure2, then the following could work for you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;merge dataset1(in=a) dataset2 (in=b);&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;if b and measure4=measure2 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if there is a chance that you may have multiple measure2 that match measure4 within the same id and you don't want duplicates, then you may try proc sql:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select distinct * from dataset1 a&lt;/P&gt;&lt;P&gt;&amp;nbsp; left join&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datset2 b&lt;/P&gt;&lt;P&gt;on a.id=b.id and measure4=measure2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: you can ignore the warning saying 'id' already existed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 14:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Need-help-in-Merge-in-Datastep-or-Join-in-Proc-SQL-please/m-p/94782#M9499</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-10-14T14:48:03Z</dc:date>
    </item>
  </channel>
</rss>

