<?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 Merging with same value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282115#M57293</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have problems when merging the data as I only get the value once:&lt;/P&gt;&lt;P&gt;(This is a simplified example but I need individual lines of observation, although they are the same. Hence, I created a matchingkey to combine the ID and Types&amp;nbsp;which is&amp;nbsp;a unique key that matches. Modified just indicates that I have modify the original data.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset1;
  input ID Types $ Date Matchingkey $;
  cards;
1  Apple Jan2016 1Apple
1  Apple Jan2016 1Apple
2  Orange . 2Orange
2  Orange . 2Orange
2  Apple Feb2016 2Apple
;

data dataset2;
  input Matchingkey $ Date Modified $;
  cards;
2Orange Jan2016 Y
;

proc sort data=dataset1;
  by Matchingkey;
run;

proc sort data=dataset2;
  by Matchingkey;
run;

data want;
  merge dataset1 (in=a) dataset2;
  by Matchingkey;
  if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, the output I get will be only:&lt;/P&gt;&lt;P&gt;ID Types Date Matchingkey Modified&lt;BR /&gt;1 Apple Jan2016 1Apple&lt;BR /&gt;1 Apple Jan2016 1Apple&lt;BR /&gt;2 Orange Jan2016 2Orange Y&lt;BR /&gt;2 Orange . 2Orange Y&lt;BR /&gt;2 Apple Feb2016 2Apple&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is there any way to merge the date to both 2Orange?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate help for this!&lt;/P&gt;&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2016 11:03:12 GMT</pubDate>
    <dc:creator>LaiQ</dc:creator>
    <dc:date>2016-07-05T11:03:12Z</dc:date>
    <item>
      <title>Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282115#M57293</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have problems when merging the data as I only get the value once:&lt;/P&gt;&lt;P&gt;(This is a simplified example but I need individual lines of observation, although they are the same. Hence, I created a matchingkey to combine the ID and Types&amp;nbsp;which is&amp;nbsp;a unique key that matches. Modified just indicates that I have modify the original data.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset1;
  input ID Types $ Date Matchingkey $;
  cards;
1  Apple Jan2016 1Apple
1  Apple Jan2016 1Apple
2  Orange . 2Orange
2  Orange . 2Orange
2  Apple Feb2016 2Apple
;

data dataset2;
  input Matchingkey $ Date Modified $;
  cards;
2Orange Jan2016 Y
;

proc sort data=dataset1;
  by Matchingkey;
run;

proc sort data=dataset2;
  by Matchingkey;
run;

data want;
  merge dataset1 (in=a) dataset2;
  by Matchingkey;
  if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, the output I get will be only:&lt;/P&gt;&lt;P&gt;ID Types Date Matchingkey Modified&lt;BR /&gt;1 Apple Jan2016 1Apple&lt;BR /&gt;1 Apple Jan2016 1Apple&lt;BR /&gt;2 Orange Jan2016 2Orange Y&lt;BR /&gt;2 Orange . 2Orange Y&lt;BR /&gt;2 Apple Feb2016 2Apple&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is there any way to merge the date to both 2Orange?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate help for this!&lt;/P&gt;&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 11:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282115#M57293</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T11:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282118#M57294</link>
      <description>&lt;P&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;data dataset1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;input ID Types $ Date :monyy7. Matchingkey $;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;cards;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;1 Apple Jan2016 1Apple&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;1 Apple Jan2016 1Apple&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2 Orange . 2Orange&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2 Orange . 2Orange&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2 Apple Feb2016 2Apple&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;data dataset2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;input Matchingkey $ Date :monyy7. Modified $;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;cards;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2Orange Jan2016 Y&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;proc sql ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;create table want1 as &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;select id, types, coalesce(d1.date,d2.date) as date format monyy7. , d1.matchingkey&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;from dataset1 as d1 left outer join dataset2 as d2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;on d1.matchingkey=d2.matchingkey;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;There is also an advantage of not needing to sort the datasets first.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you wanted to not use&amp;nbsp;the matchingkey variable and have the variables id &amp;amp; types in both&lt;BR /&gt;datasets, then you could change the match conditions of the sql procedure to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;on d1.id=d2.id AND d1.types=d2.types&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 11:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282118#M57294</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-07-05T11:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282119#M57295</link>
      <description>&lt;P&gt;Thank you! Really appreciate it cus I'm not well-versed with SQL but will try it! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 11:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282119#M57295</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T11:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282125#M57296</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82677"&gt;@LaiQ﻿&lt;/a&gt;&lt;/P&gt;&lt;P&gt;The following will also work, using a data step merge.&lt;/P&gt;&lt;P&gt;I would still prefer to use the proc sql join though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;data dataset1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;input ID Types $ Date :monyy7. Matchingkey $;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;cards;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;1 Apple Jan2016 1Apple&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;1 Apple Jan2016 1Apple&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2 Orange . 2Orange&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2 Orange . 2Orange&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2 Apple Feb2016 2Apple&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;data dataset2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;input Matchingkey $ Date :monyy7. Modified $;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;cards;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;2Orange Jan2016 Y&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;proc sort data=dataset1; by matchingkey;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;proc sort data=dataset2; by matchingkey;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;data want (drop= d1 d2);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;merge dataset1 (rename=(date=d1)) dataset2 (rename=(date=d2));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;by matchingkey;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;date=coalesce(d1,d2);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;format date monyy7.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="comic sans ms,sans-serif"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 12:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282125#M57296</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-07-05T12:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282129#M57297</link>
      <description>&lt;P&gt;Note there is not any need to combine variables to create a single variable that can be used as a key.&lt;/P&gt;
&lt;P&gt;You can just reference both variables in your BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge one two ;
  by id type ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282129#M57297</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-05T13:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282130#M57298</link>
      <description>&lt;P&gt;Yes, after trying, I think SQL runs much much faster than proc merge. However, will it be able to replace missing values only? Meaning to read that d1.date is missing then will match over, else if d1.date is filled - do not match/join.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282130#M57298</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T13:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282131#M57299</link>
      <description>&lt;P&gt;Noted! However, in my actual data, I have 8 variables that needs to match exactly. Hence, it might take a long time for SAS to sort and I have over 8 million observations... Hence, perhaps a matching key will save me time.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282131#M57299</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T13:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282132#M57300</link>
      <description>&lt;P&gt;That is what the COALESCE() function does. It will take the first non-missing value amoung the list of arguments.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282132#M57300</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-05T13:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282133#M57301</link>
      <description>&lt;P&gt;It will not take any longer to sort on 8 variables than on one.&lt;/P&gt;
&lt;P&gt;You will just have to write more code, espcecially if using PROC SQL since you will need to wite out all of the join conditions.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282133#M57301</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-05T13:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282134#M57302</link>
      <description>&lt;P&gt;Yes, actually I used SQL with 7 AND condition. It does work fine, but just that now all the observations in my want dataset contains MODIFIED = "Y" because it matches all the condition but I want this to apply to only the observations with empty dates. Do I have to extract all the empty dates from the dataset1 first, merged with dataset2, then patch it back to my dataset1? Meaning my dataset2 contains 1Apple as well - as I'm using the full dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282134#M57302</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T13:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282136#M57303</link>
      <description>&lt;P&gt;Not sure what you mean so let me re-phrase it and then answer.&lt;/P&gt;
&lt;P&gt;You want to update one variable, DATE, in the first dataset with another variable, also named DATE, from another dataset. But you only want to use the records from the second dataset that indicate they are modifications, MODIFIED='Y'. &amp;nbsp;You have 8 key variables, call them ID1-ID8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is all that&amp;nbsp;you want to do then obviously you only want to read the records from the second dataset that have MODIFIED='Y'. &amp;nbsp;Not sure why there are any other records there if its purpose is to modify the first dataset but the easiest way to make sure you don't use the other records is to exclude them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So here is data step code that combines the data set and modifes DATE only when the MODIFIED flag is set. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge one
        two (keep=id1-id8 date modified rename=(date=newdate)
                     where=(modified='Y') )
  ;
  by id1-id8;
  if modified='Y' then date=newdate;
  drop newdate modified;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282136#M57303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-05T13:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282138#M57304</link>
      <description>&lt;P&gt;Ooh, I see. That really explains much clearer. I will go try it out.&lt;/P&gt;&lt;P&gt;Really sorry for the confusion, but you really helped me a lot! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 13:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282138#M57304</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T13:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282145#M57307</link>
      <description>&lt;P&gt;Adapting the SQL solution for the case to match the conditions that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;&amp;nbsp;has suggested&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want1 as 
select d1.id, d1.types, coalesce(d1.date,d2.date) as date format monyy7., modified
from dataset1 as d1 left outer join dataset2 as d2
on d1.id=d2.id and d1.types=d2.types and d2.modified='Y';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or &amp;nbsp;another alternative&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want2 as 
select d1.id, d1.types, coalesce(d1.date,d2.date) as date format monyy7., modified
from dataset1 as d1 left outer join dataset2 (where=(modified='Y')) as d2
on d1.id=d2.id and d1.types=d2.types ;
run;
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You also stated that you "&lt;SPAN&gt;want this to apply to only the observations with empty dates" .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So yet another variation&amp;nbsp;would be&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want3 as 
select d1.id, d1.types, coalesce(d1.date,d2.date) as date format monyy7., modified
from dataset1 as d1 left outer join dataset2 as d2
on d1.id=d2.id and d1.types=d2.types and d1.date=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 14:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282145#M57307</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-07-05T14:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282237#M57331</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36257"&gt;@JohnHoughton﻿&lt;/a&gt;! The last one works as what I want it to be!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate your time to get back to me. Thank you! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 18:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-same-value/m-p/282237#M57331</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-07-05T18:10:14Z</dc:date>
    </item>
  </channel>
</rss>

