<?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: When merging two data sets, some items remain unmatched in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913462#M360044</link>
    <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Acquiror_6digit_CUSIP&lt;/TD&gt;&lt;TD&gt;Date_Announced&lt;/TD&gt;&lt;TD&gt;Acquiror_Full_Name&lt;/TD&gt;&lt;TD&gt;Acquiror_8digit_CUSIP&lt;/TD&gt;&lt;TD&gt;PERMNO&lt;/TD&gt;&lt;TD&gt;NAMEDT&lt;/TD&gt;&lt;TD&gt;NAMEENDT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;466032&lt;/TD&gt;&lt;TD&gt;3.01.2017&lt;/TD&gt;&lt;TD&gt;J&amp;amp;J SNACK FOODS CORP&lt;/TD&gt;&lt;TD&gt;46603210&lt;/TD&gt;&lt;TD&gt;10026&lt;/TD&gt;&lt;TD&gt;10.06.2004&lt;/TD&gt;&lt;TD&gt;4.08.2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;466032&lt;/TD&gt;&lt;TD&gt;17.08.2017&lt;/TD&gt;&lt;TD&gt;J&amp;amp;J SNACK FOODS CORP&lt;/TD&gt;&lt;TD&gt;46603210&lt;/TD&gt;&lt;TD&gt;10026&lt;/TD&gt;&lt;TD&gt;10.06.2004&lt;/TD&gt;&lt;TD&gt;4.08.2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;68389X&lt;/TD&gt;&lt;TD&gt;19.01.2017&lt;/TD&gt;&lt;TD&gt;ORACLE CORP&lt;/TD&gt;&lt;TD&gt;68389X10&lt;/TD&gt;&lt;TD&gt;10104&lt;/TD&gt;&lt;TD&gt;15.07.2013&lt;/TD&gt;&lt;TD&gt;30.12.2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;68389X&lt;/TD&gt;&lt;TD&gt;18.12.2017&lt;/TD&gt;&lt;TD&gt;ORACLE CORP&lt;/TD&gt;&lt;TD&gt;68389X10&lt;/TD&gt;&lt;TD&gt;10104&lt;/TD&gt;&lt;TD&gt;15.07.2013&lt;/TD&gt;&lt;TD&gt;30.12.2022&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of matched data, first column is from one table and the last two columns are from another table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I match them using CUSIP. In the first table, I set the format of CUSIP as 6.. In the second table I cut the 8digit CUSIP to 6 digits and make sure the formats of dates also match between two tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data MA3;&lt;BR /&gt;set Zeynep.Dsenames;&lt;BR /&gt;NCUSIP=substr(CUSIP,1,6);&lt;BR /&gt;format NAMEDT DATE9. NAMEENDT DATE9. NCUSIP 6.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To merge two tables I use the following code:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join MA3&lt;BR /&gt;on MA2.Date_Announced&lt;BR /&gt;between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and MA2.Acquiror_6digit_CUSIP = upcase(MA3.NCUSIP) ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This process results in 2200 matched and 800 unmatched items. I get an output of the unmatched items and manually see that they should also match the second table (I also got excel outputs and matched them using vlookup function) based on CUSIP and dates.&lt;/P&gt;&lt;P&gt;CUSIP are 6 digit character for both datasets and dates are in Num DATE9. format in both datasets. I check these using proc contents. I can confirm that there are no spaces as if there were they wouldn't match in excel as well.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jan 2024 18:52:52 GMT</pubDate>
    <dc:creator>merveayibogan</dc:creator>
    <dc:date>2024-01-29T18:52:52Z</dc:date>
    <item>
      <title>When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913375#M360014</link>
      <description>&lt;P&gt;I have two datasets. The first one (MA2) includes event date and identifier. The second one (MA3) includes identifier, date identifier started, date identifier ended. In MA2 there are multiple dates with the same identifier. In MA3, there are also time periods (date identifier started - date identifier ended)&amp;nbsp;with same or different identifiers. I am trying to merge these by the following code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join MA3&lt;BR /&gt;on MA2.Date_Announced&lt;BR /&gt;between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and MA2.Acquiror_6digit_CUSIP = upcase(MA3.NCUSIP) ;&lt;BR /&gt;quit;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some items in MA2 remain unmatched even though in raw data I can see that there are corresponding items in MA3 that they should match. Can you help me on this problem ?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 12:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913375#M360014</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-01-29T12:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913385#M360022</link>
      <description>&lt;P&gt;Provide actual example data of the values that "match" that the code does show a match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quite often there are things in the values that are not exactly equal but you do not see the difference.&lt;/P&gt;
&lt;P&gt;If the values are numeric then the format may be showing a rounded value that appears to match.&lt;/P&gt;
&lt;P&gt;Depending on how you look at your data you may have one or more leading or embedded spaces in a character variable that you don't see clearly but the code uses in comparisons. Or case of character values.&lt;/P&gt;
&lt;P&gt;Or custom formats applied to values where the actual values are quite different than what you "see".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly how did you decide that there are values that should match but didn't?&lt;/P&gt;
&lt;P&gt;Here is an example of a variable with 4 different values differing by leading spaces but Proc Print and most output by default will show them as "the same":&lt;/P&gt;
&lt;PRE&gt;data example;
   x="   word";output;
   x="  word";output;
   x=" word";output;
   x="word";output;
run;

proc print data=example;
run;&lt;/PRE&gt;
&lt;P&gt;Default output looks like:&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;A name="IDX2" target="_blank"&gt;&lt;/A&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.EXAMPLE" cellspacing="0" cellpadding="3"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c m header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;x&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;word&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;word&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;word&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;word&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or Proc freq:&lt;/P&gt;
&lt;PRE&gt;proc freq data=example;
run;&lt;/PRE&gt;
&lt;P&gt;which detects the difference but doesn't actually show it in the output:&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;A name="IDX3" target="_blank"&gt;&lt;/A&gt;
&lt;DIV class="l proctitle"&gt;The FREQ Procedure&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Freq: One-Way Frequencies" cellspacing="0" cellpadding="3"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l m header" scope="col"&gt;x&lt;/TH&gt;
&lt;TH class="r m header" scope="col"&gt;Frequency&lt;/TH&gt;
&lt;TH class="r m header" scope="col"&gt;Percent&lt;/TH&gt;
&lt;TH class="r m header" scope="col"&gt;Cumulative&lt;BR /&gt;Frequency&lt;/TH&gt;
&lt;TH class="r m header" scope="col"&gt;Cumulative&lt;BR /&gt;Percent&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;word&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;25.00&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;25.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;word&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;25.00&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;50.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;word&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;25.00&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;75.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;word&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;25.00&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;100.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Freq counts each value as different but the display in output appears the same.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 29 Jan 2024 13:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913385#M360022</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-29T13:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913462#M360044</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Acquiror_6digit_CUSIP&lt;/TD&gt;&lt;TD&gt;Date_Announced&lt;/TD&gt;&lt;TD&gt;Acquiror_Full_Name&lt;/TD&gt;&lt;TD&gt;Acquiror_8digit_CUSIP&lt;/TD&gt;&lt;TD&gt;PERMNO&lt;/TD&gt;&lt;TD&gt;NAMEDT&lt;/TD&gt;&lt;TD&gt;NAMEENDT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;466032&lt;/TD&gt;&lt;TD&gt;3.01.2017&lt;/TD&gt;&lt;TD&gt;J&amp;amp;J SNACK FOODS CORP&lt;/TD&gt;&lt;TD&gt;46603210&lt;/TD&gt;&lt;TD&gt;10026&lt;/TD&gt;&lt;TD&gt;10.06.2004&lt;/TD&gt;&lt;TD&gt;4.08.2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;466032&lt;/TD&gt;&lt;TD&gt;17.08.2017&lt;/TD&gt;&lt;TD&gt;J&amp;amp;J SNACK FOODS CORP&lt;/TD&gt;&lt;TD&gt;46603210&lt;/TD&gt;&lt;TD&gt;10026&lt;/TD&gt;&lt;TD&gt;10.06.2004&lt;/TD&gt;&lt;TD&gt;4.08.2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;68389X&lt;/TD&gt;&lt;TD&gt;19.01.2017&lt;/TD&gt;&lt;TD&gt;ORACLE CORP&lt;/TD&gt;&lt;TD&gt;68389X10&lt;/TD&gt;&lt;TD&gt;10104&lt;/TD&gt;&lt;TD&gt;15.07.2013&lt;/TD&gt;&lt;TD&gt;30.12.2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;68389X&lt;/TD&gt;&lt;TD&gt;18.12.2017&lt;/TD&gt;&lt;TD&gt;ORACLE CORP&lt;/TD&gt;&lt;TD&gt;68389X10&lt;/TD&gt;&lt;TD&gt;10104&lt;/TD&gt;&lt;TD&gt;15.07.2013&lt;/TD&gt;&lt;TD&gt;30.12.2022&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of matched data, first column is from one table and the last two columns are from another table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I match them using CUSIP. In the first table, I set the format of CUSIP as 6.. In the second table I cut the 8digit CUSIP to 6 digits and make sure the formats of dates also match between two tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data MA3;&lt;BR /&gt;set Zeynep.Dsenames;&lt;BR /&gt;NCUSIP=substr(CUSIP,1,6);&lt;BR /&gt;format NAMEDT DATE9. NAMEENDT DATE9. NCUSIP 6.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To merge two tables I use the following code:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join MA3&lt;BR /&gt;on MA2.Date_Announced&lt;BR /&gt;between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and MA2.Acquiror_6digit_CUSIP = upcase(MA3.NCUSIP) ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This process results in 2200 matched and 800 unmatched items. I get an output of the unmatched items and manually see that they should also match the second table (I also got excel outputs and matched them using vlookup function) based on CUSIP and dates.&lt;/P&gt;&lt;P&gt;CUSIP are 6 digit character for both datasets and dates are in Num DATE9. format in both datasets. I check these using proc contents. I can confirm that there are no spaces as if there were they wouldn't match in excel as well.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 18:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913462#M360044</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-01-29T18:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913467#M360045</link>
      <description>&lt;P&gt;There seems to be a disconnect there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SUBSTR() will return a CHARACTER value.&lt;/P&gt;
&lt;P&gt;The 6. format is something you would apply to a NUMERIC value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the variable type character or numeric?&amp;nbsp; Is the type the same in both sources?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 19:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913467#M360045</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-29T19:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913474#M360048</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462592"&gt;@merveayibogan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Acquiror_6digit_CUSIP&lt;/TD&gt;
&lt;TD&gt;Date_Announced&lt;/TD&gt;
&lt;TD&gt;Acquiror_Full_Name&lt;/TD&gt;
&lt;TD&gt;Acquiror_8digit_CUSIP&lt;/TD&gt;
&lt;TD&gt;PERMNO&lt;/TD&gt;
&lt;TD&gt;NAMEDT&lt;/TD&gt;
&lt;TD&gt;NAMEENDT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;466032&lt;/TD&gt;
&lt;TD&gt;3.01.2017&lt;/TD&gt;
&lt;TD&gt;J&amp;amp;J SNACK FOODS CORP&lt;/TD&gt;
&lt;TD&gt;46603210&lt;/TD&gt;
&lt;TD&gt;10026&lt;/TD&gt;
&lt;TD&gt;10.06.2004&lt;/TD&gt;
&lt;TD&gt;4.08.2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;466032&lt;/TD&gt;
&lt;TD&gt;17.08.2017&lt;/TD&gt;
&lt;TD&gt;J&amp;amp;J SNACK FOODS CORP&lt;/TD&gt;
&lt;TD&gt;46603210&lt;/TD&gt;
&lt;TD&gt;10026&lt;/TD&gt;
&lt;TD&gt;10.06.2004&lt;/TD&gt;
&lt;TD&gt;4.08.2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;68389X&lt;/TD&gt;
&lt;TD&gt;19.01.2017&lt;/TD&gt;
&lt;TD&gt;ORACLE CORP&lt;/TD&gt;
&lt;TD&gt;68389X10&lt;/TD&gt;
&lt;TD&gt;10104&lt;/TD&gt;
&lt;TD&gt;15.07.2013&lt;/TD&gt;
&lt;TD&gt;30.12.2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;68389X&lt;/TD&gt;
&lt;TD&gt;18.12.2017&lt;/TD&gt;
&lt;TD&gt;ORACLE CORP&lt;/TD&gt;
&lt;TD&gt;68389X10&lt;/TD&gt;
&lt;TD&gt;10104&lt;/TD&gt;
&lt;TD&gt;15.07.2013&lt;/TD&gt;
&lt;TD&gt;30.12.2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is an example of matched data, first column is from one table and the last two columns are from another table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I match them using CUSIP. In the first table, I set the format of CUSIP as 6.. In the second table I cut the 8digit CUSIP to 6 digits and make sure the formats of dates also match between two tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data MA3;&lt;BR /&gt;set Zeynep.Dsenames;&lt;BR /&gt;NCUSIP=substr(CUSIP,1,6);&lt;BR /&gt;format NAMEDT DATE9. NAMEENDT DATE9. NCUSIP 6.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To merge two tables I use the following code:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join MA3&lt;BR /&gt;on MA2.Date_Announced&lt;BR /&gt;between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and MA2.Acquiror_6digit_CUSIP = upcase(MA3.NCUSIP) ;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This process results in 2200 matched and 800 unmatched items. I get an output of the unmatched items and manually see that they should also match the second table (I also got excel outputs and matched them using vlookup function) based on CUSIP and dates.&lt;/P&gt;
&lt;P&gt;CUSIP are 6 digit character for both datasets and dates are in Num DATE9. format in both datasets. I check these using proc contents. I can confirm that there are no spaces as if there were they wouldn't match in excel as well.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your picture doesn't show any variable named CUSIP or result named NCUSIP so hard to tell how the code relates to that picture.&lt;/P&gt;
&lt;P&gt;Note, if a value has a leading space then substr(CUSIP,1,6) will continue to have that leading space. IF however CUSIP is a numeric value then you really never want to use SUBSTR on it without actually controlling the conversion of numeric to character values that the Substr function will work with.&lt;/P&gt;
&lt;P&gt;Consider this example:&lt;/P&gt;
&lt;PRE&gt;233  data example;
234    x=123;
235    z= substr(x,1,6);
236  run;

NOTE: Numeric values have been converted to character
      values at the places given by: (Line):(Column).
      235:13
&lt;/PRE&gt;
&lt;P&gt;You could copy out the data step and run this. If you cannot tell me know quickly why the value of Z is blank in this example then your CUSIP variable better not be numeric. When you see that "Numeric values have been converted to character" then SAS applied internal rules which involve the BEST12. format. So the Substr function was applied to a string with the value "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123". That is 9 leading blanks because there were only 3 digits. If your Cusip is numeric and 8 characters the result would have 4 leading blanks. The example has Z blank because 1 through 6 were all blank characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your questions are about UNMATCHED data then you should provide examples of that. In a way that we know what the actual values in your data set are. As my previous example shows, printed tables can hide the differences in values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as the values are of the same type, numeric or character, then the format makes no difference for comparisons or calculations.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 21:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913474#M360048</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-29T21:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913526#M360060</link>
      <description>&lt;P&gt;They are both characters.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 08:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913526#M360060</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-01-30T08:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913534#M360061</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thank you very much for your time and responses. Below is an example of unmatched data in MA2:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Acquiror_6digit_CUSIP&lt;/TD&gt;&lt;TD&gt;Date_Announced&lt;/TD&gt;&lt;TD&gt;Acquiror_Full_Name&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;09253U&lt;/TD&gt;&lt;TD&gt;10/02/2017&lt;/TD&gt;&lt;TD&gt;Blackstone Group LP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;09253U&lt;/TD&gt;&lt;TD&gt;20/03/2017&lt;/TD&gt;&lt;TD&gt;Blackstone Group LP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;09253U&lt;/TD&gt;&lt;TD&gt;27/11/2017&lt;/TD&gt;&lt;TD&gt;Blackstone Group LP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;G0408V&lt;/TD&gt;&lt;TD&gt;03/05/2017&lt;/TD&gt;&lt;TD&gt;Aon PLC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;G0408V&lt;/TD&gt;&lt;TD&gt;01/09/2017&lt;/TD&gt;&lt;TD&gt;Aon PLC&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the corresponding lines in the other file (MA3) that should have matched:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PERMNO&lt;/TD&gt;&lt;TD&gt;NAMEDT&lt;/TD&gt;&lt;TD&gt;NAMEENDT&lt;/TD&gt;&lt;TD&gt;NCUSIP&lt;/TD&gt;&lt;TD&gt;COMNAM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;61735&lt;/TD&gt;&lt;TD&gt;02/04/2012&lt;/TD&gt;&lt;TD&gt;07/01/2014&lt;/TD&gt;&lt;TD&gt;G0408V10&lt;/TD&gt;&lt;TD&gt;AON PLC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;61735&lt;/TD&gt;&lt;TD&gt;08/01/2014&lt;/TD&gt;&lt;TD&gt;23/11/2014&lt;/TD&gt;&lt;TD&gt;G0408V10&lt;/TD&gt;&lt;TD&gt;AON PLC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;61735&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;24/11/2014&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;31/03/2020&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;G0408V10&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;AON PLC&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;92108&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;22/06/2007&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;30/06/2019&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;09253U10&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;BLACKSTONE GROUP LP&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 08:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913534#M360061</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-01-30T08:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913566#M360062</link>
      <description>&lt;P&gt;Using your code and sample data returns a result where the "unmatched" rows match.&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.MA2;
  infile datalines truncover dlm=' ';
  input Acquiror_6digit_CUSIP:$6. Date_Announced:ddmmyy10. Acquiror_Full_Name $40.;
  format Date_Announced date9.;
  datalines;
09253U 10/02/2017 Blackstone Group LP
09253U 20/03/2017 Blackstone Group LP
09253U 27/11/2017 Blackstone Group LP
G0408V 3/05/2017 Aon PLC
G0408V 1/09/2017 Aon PLC
;

data work.Dsenames;
  infile datalines truncover dlm=' ';
  input PERMNO:best32. NAMEDT:ddmmyy10. NAMEENDT:ddmmyy10. CUSIP:$8. COMNAM $40.;
  format NAMEDT NAMEENDT date9.;
  datalines;
61735 2/04/2012 7/01/2014 G0408V10 AON PLC
61735 8/01/2014 23/11/2014 G0408V10 AON PLC
61735 24/11/2014 31/03/2020 G0408V10 AON PLC
92108 22/06/2007 30/06/2019 09253U10 BLACKSTONE GROUP LP
;

data work.MA3;
  set work.Dsenames;
  NCUSIP=substr(CUSIP,1,6);
run;

proc sql;
  create table MA4 as
  select MA2.*, MA3.*
  from MA2 inner join MA3
    on MA2.Date_Announced between MA3.NAMEDT and MA3.NAMEENDT
      and MA2.Acquiror_6digit_CUSIP = upcase(MA3.NCUSIP)
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1706613088484.png" style="width: 703px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93064iA4EE6F0578CA5980/image-dimensions/703x111?v=v2" width="703" height="111" role="button" title="Patrick_1-1706613088484.png" alt="Patrick_1-1706613088484.png" /&gt;&lt;/span&gt;&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;As others already "hinted": Only because values display the same way doesn't mean that they are exactly the same. The most likely difference are leading blanks. Try if below SQL returns the expected result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table MA4 as
  select MA2.*, MA3.*
  from MA2 inner join Zeynep.Dsenames as MA3
    on MA2.Date_Announced between MA3.NAMEDT and MA3.NAMEENDT
      and strip(MA2.Acquiror_6digit_CUSIP) = upcase(substr(strip(MA3.NCUSIP),1,6)))
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's still not working then some other non-print character like a tab could create the experienced issue. Try below code in such a case and let us know if that resolves the issue.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table MA4 as
  select MA2.*, MA3.*
  from MA2 inner join Zeynep.Dsenames as MA3
    on MA2.Date_Announced between MA3.NAMEDT and MA3.NAMEENDT
      and upcase(compress(MA2.Acquiror_6digit_CUSIP,,'kn')) = upcase(substr(compress(MA3.NCUSIP,,'kn'),1,6))
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 11:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913566#M360062</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-30T11:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913855#M360142</link>
      <description>&lt;P&gt;this solution increased the number of matched items. however, my main data has 3000 items, after applying the code you shared, 2300 items are merged using the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join Zeynep.Dsenames as MA3&lt;BR /&gt;on MA2.Date_Announced between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and strip(MA2.Acquiror_6digit_CUSIP) = upcase(substr(strip(MA3.NCUSIP),1,6))&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To see which items are not matched I use the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Unmatched_MA3 as&lt;BR /&gt;select MA2.Acquiror_6digit_CUSIP, MA2.Date_Announced, MA2.Acquiror_Full_Name&lt;BR /&gt;from MA2 left join MA3&lt;BR /&gt;on MA2.Acquiror_6digit_CUSIP = MA3.NCUSIP&lt;BR /&gt;where MA3.NCUSIP is missing;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this results in 800 observations. I would expect that the number of observations in matched and unmatched datasets would sum up to 3000.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of getting a merged and unmatched output, can I change the below code some way that unmatched items are displayed as missing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join Zeynep.Dsenames as MA3&lt;BR /&gt;on MA2.Date_Announced between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and strip(MA2.Acquiror_6digit_CUSIP) = upcase(substr(strip(MA3.NCUSIP),1,6))&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 17:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913855#M360142</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-01-31T17:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913899#M360161</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462592"&gt;@merveayibogan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this solution increased the number of matched items. however, my main data has 3000 items, after applying the code you shared, 2300 items are merged using the code below:&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;To see which items are not matched I use the code below:&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;this results in 800 observations. I would expect that the number of observations in matched and unmatched datasets would sum up to 3000.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have likely one to many or even many to many scenarios in your data and though can end-up with more rows than expected. To find the explanation why you're getting these 800 instead of the expected 700 unmatched rows is exactly what you need to do.&lt;/P&gt;
&lt;P&gt;For example: Could your cusip variables be missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Instead of getting a merged and unmatched output, can I change the below code some way that unmatched items are displayed as missing:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could use code along the line of below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  set sashelp.class(keep=name);
  retain src_flg1 1;
  if _n_ in (2,3) then call missing(name);
  if _n_ in (5) then delete;
run;

data have2;
  set sashelp.class(keep=name);
  retain src_flg2 1;
  if _n_ in (3,4) then call missing(name);
  if _n_ in (6) then delete;
run;

proc sql;
  select 
    h1.src_flg1,
    h2.src_flg2,
    h1.name as h1_name, 
    h2.name as h2_name
  from have1 h1 full join have2 h2
  on h1.name=h2.name
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 23:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913899#M360161</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-31T23:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913915#M360167</link>
      <description>&lt;P&gt;Some of that data does not match because the date does not fall into the range.&lt;/P&gt;
&lt;P&gt;How important is it to match the date range?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's convert your listing into actual SAS datasets (and fix the way the dates are displayed so they don't confuse 50% of the audience).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  infile cards dsd dlm='|' truncover;
  input Acquiror_6digit_CUSIP :$6. Date_Announced :ddmmyy. Acquiror_Full_Name :$30. ;
  format Date_Announced yymmdd10.;
cards;
09253U|10/02/2017|Blackstone Group LP
09253U|20/03/2017|Blackstone Group LP
09253U|27/11/2017|Blackstone Group LP
G0408V|03/05/2017|Aon PLC
G0408V|01/09/2017|Aon PLC
;

data have2;
  infile cards dsd dlm='|' truncover;
  input PERMNO :$10. NAMEDT :ddmmyy. NAMEENDT :ddmmyy. NCUSIP :$8. COMNAM :$30.;
  format NAMEDT NAMEENDT yymmdd10.;
cards;
61735|02/04/2012|07/01/2014|G0408V10|AON PLC
61735|08/01/2014|23/11/2014|G0408V10|AON PLC
61735|24/11/2014|31/03/2020|G0408V10|AON PLC
92108|22/06/2007|30/06/2019|09253U10|BLACKSTONE GROUP LP
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can just do a FULL join so we can see where ALL of the records end up.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table match as 
  select 
      coalesce(a.Acquiror_6digit_CUSIP,substr(left(b.NCUSIP),1,6)) as CUSIP6 
    , a.Acquiror_6digit_CUSIP
    , a.Date_Announced
    , b.NAMEDT
    , b.NAMEENDT
    , a.Acquiror_Full_Name
    , b.PERMNO
    , b.NCUSIP
    , b.COMNAM
  from have1 a
   full join have2 b
   on a.Acquiror_6digit_CUSIP = substr(left(b.NCUSIP),1,6)
   and a.Date_Announced between b.NAMEDT and b.NAMEENDT
  order by 1,2,3,4,5
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1706765489876.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93138iC453FD5FC125C9DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1706765489876.png" alt="Tom_0-1706765489876.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 05:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913915#M360167</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-01T05:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913928#M360173</link>
      <description>&lt;P&gt;thank you for your response, the code works except that have1 has 3000 observations, have2 has 100000 observations. I want to have the final output to have 3000 observations, some items matched with have2 some unmatched. using this code, i have an output with around 100000 observations.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 07:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913928#M360173</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-02-01T07:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913929#M360174</link>
      <description>&lt;P&gt;yes there are many to many for one criteria (cusip), the second criteria (date) ensures that there is only one match for the first criteria. there are no missing variables. I can't use full join, I want the final output to have as many observations as in the first dataset. in the second dataset there are many irrelevant observations.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 07:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913929#M360174</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-02-01T07:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913935#M360175</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462592"&gt;@merveayibogan&lt;/a&gt;&amp;nbsp;To fully clarify what you have and what you want it's may-be best if you share representative sample data (you could use what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;already created as starting point), show us the desired result using this data and explain the logic to create this result.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 08:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/913935#M360175</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-01T08:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/914036#M360188</link>
      <description>&lt;P&gt;Ok, the first dataset looks like this. The name of the file is MA2. I use the Acquiror_6digit_CUSIP and Date_Announced columns to merge it with the second dataset MA3 which I am also sharing.&lt;/P&gt;&lt;P&gt;MA2:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="merveayibogan_0-1706801962334.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93154i6595AB857CF1415E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="merveayibogan_0-1706801962334.png" alt="merveayibogan_0-1706801962334.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;MA3:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="merveayibogan_1-1706802147914.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93155i9DC99DFA0799724C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="merveayibogan_1-1706802147914.png" alt="merveayibogan_1-1706802147914.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MA2 has 3000 observations, MA3 has 100000 observations. I am trying to merge these two with the following criteria:&lt;/P&gt;&lt;P&gt;MA2.Acquiror_6digit_CUSIP is equal to MA3.NCUSIP and MA2.Date_Announced is between MA3.NAMEDT and MA3.NAMEENDT.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, I am using this code:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table MA4 as&lt;BR /&gt;select MA2.*, MA3.*&lt;BR /&gt;from MA2 inner join Zeynep.Dsenames as MA3&lt;BR /&gt;on MA2.Date_Announced between MA3.NAMEDT and MA3.NAMEENDT&lt;BR /&gt;and strip(MA2.Acquiror_6digit_CUSIP) = upcase(substr(strip(MA3.NCUSIP),1,6))&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result of this looks exactly like I want where I can see all the columns in both datasets if they are matched with my criteria. However, this result contains 2400 observations while MA2 had 3000. So I basically want to be able to see 3000 observations in the final output. 2400 of them should be matched with MA3 and 600 should display missing values. I hope I explained it. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 15:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/914036#M360188</guid>
      <dc:creator>merveayibogan</dc:creator>
      <dc:date>2024-02-01T15:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: When merging two data sets, some items remain unmatched</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/914039#M360189</link>
      <description>&lt;P&gt;You did an INNER JOIN so you only get the observations that match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want all observations from MA2 included you need to do a LEFT JOIN.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want LEFT JOIN instead of RIGHT JOIN because MA2 is dataset on the left hand side of the JOIN keyword.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 16:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-merging-two-data-sets-some-items-remain-unmatched/m-p/914039#M360189</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-01T16:10:05Z</dc:date>
    </item>
  </channel>
</rss>

