<?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: conditional merge of two data sets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425886#M13121</link>
    <description>&lt;P&gt;changing do lt (less than&amp;lt;&amp;nbsp;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *,&lt;STRONG&gt;intck('month',testdate1,testdate2)&amp;lt;6&lt;/STRONG&gt; as indicator&lt;BR /&gt;from have1 a, have2(rename=(testdate1=testdate2)) b&lt;BR /&gt;where a.id=b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2018 19:58:34 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-08T19:58:34Z</dc:date>
    <item>
      <title>conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425863#M13109</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to merge two data sets. One of the datasets looks like:&lt;/P&gt;&lt;P&gt;ID testdate1&lt;/P&gt;&lt;P&gt;1 09/30/2015&lt;/P&gt;&lt;P&gt;1 06/15/2016&lt;/P&gt;&lt;P&gt;1 01/05/2017&lt;/P&gt;&lt;P&gt;2 03/20/2017&lt;/P&gt;&lt;P&gt;2 04/22/2017&lt;/P&gt;&lt;P&gt;The number of records for each person varies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 2nd data set looks like:&lt;/P&gt;&lt;P&gt;ID testdate2&lt;/P&gt;&lt;P&gt;1 07/06/2016&lt;/P&gt;&lt;P&gt;1 01/02/2017&lt;/P&gt;&lt;P&gt;2 05/19/2017&lt;/P&gt;&lt;P&gt;2 10/20/2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can only match them using ID. What I want is:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; testdate1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testdate2&amp;nbsp;&amp;nbsp;&amp;nbsp; Indicator&lt;/P&gt;&lt;P&gt;1 06/15/2016&amp;nbsp;&amp;nbsp; 07/06/2016&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 01/05/2017&amp;nbsp; 01/02/2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the interval between testdate1 and testdate2 is greater than 6 months, an indicator variable will be coded 1, otherwise the indicator variable is coded 0.&lt;/P&gt;&lt;P&gt;When I used the ID to merge the two datasets, it turns out to be&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; testdate1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testdate2&amp;nbsp;&amp;nbsp; Indicator&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 09/30/2015 07/06/2016&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1 06/15/2016&amp;nbsp;&amp;nbsp; 01/02/2017 0&lt;/P&gt;&lt;P&gt;1 01/05/2017&amp;nbsp; 01/02/2017&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the merged dataset above, the first person is mismatched. I want testdate1=06/15/2016 to be matched with 07/06/2016 and testdate1=09/30/2015 should not be matched with any records in data set 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425863#M13109</guid>
      <dc:creator>newbe</dc:creator>
      <dc:date>2018-01-08T19:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425875#M13113</link>
      <description>&lt;P&gt;Show us your code and log. Let's see if we can modify it. If nothing works out, we shall work on a new solution&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425875#M13113</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-08T19:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425879#M13116</link>
      <description>&lt;P&gt;My code is simple, but I don't think it is correct.&lt;/P&gt;&lt;P&gt;proc sort data=one;&lt;/P&gt;&lt;P&gt;by ID descending testdate1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=two;&lt;/P&gt;&lt;P&gt;by ID descending testdate2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data three;&lt;/P&gt;&lt;P&gt;merge one two;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created another variable in data set 1 and 2 by counting the number of observations for each person and then merge the two datasets using ID and the count. I am not sure whether this is correct.&lt;/P&gt;&lt;P&gt;data one1;&lt;/P&gt;&lt;P&gt;set one;&lt;/P&gt;&lt;P&gt;by ID descending testdate1;&lt;/P&gt;&lt;P&gt;if first.ID then count=0;&lt;/P&gt;&lt;P&gt;count+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two1;&lt;/P&gt;&lt;P&gt;set two;&lt;/P&gt;&lt;P&gt;by ID descending testdate2;&lt;/P&gt;&lt;P&gt;if first.ID then count=0;&lt;/P&gt;&lt;P&gt;count+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data all;&lt;/P&gt;&lt;P&gt;merge one1 two1;&lt;/P&gt;&lt;P&gt;by ID count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425879#M13116</guid>
      <dc:creator>newbe</dc:creator>
      <dc:date>2018-01-08T19:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425883#M13118</link>
      <description>&lt;P&gt;seems like sql is better for this this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input iD testdate1 :mmddyy10.;&lt;BR /&gt;format testdate1 mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 09/30/2015&lt;BR /&gt;1 06/15/2016&lt;BR /&gt;1 01/05/2017&lt;BR /&gt;2 03/20/2017&lt;BR /&gt;2 04/22/2017&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;input iD testdate1 :mmddyy10.;&lt;BR /&gt;format testdate1 mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 07/06/2016&lt;BR /&gt;1 01/02/2017&lt;BR /&gt;2 05/19/2017&lt;BR /&gt;2 10/20/2017&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try and let me know&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *,intck('month',testdate1,testdate2)&amp;gt;6 as indicator&lt;BR /&gt;from have1 a, have2(rename=(testdate1=testdate2)) b&lt;BR /&gt;where a.id=b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425883#M13118</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-08T19:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425884#M13119</link>
      <description>&lt;P&gt;My description of the problem is not clear. Let me try again. What I really want is an indicator variable in the merged data set with a code of 1 indicating the time interval between testdate2 and testdate1 is less than 6 months and a code of 0 if the time interval between testdate2 and testdate1 is more than 6 months.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425884#M13119</guid>
      <dc:creator>newbe</dc:creator>
      <dc:date>2018-01-08T19:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425886#M13121</link>
      <description>&lt;P&gt;changing do lt (less than&amp;lt;&amp;nbsp;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *,&lt;STRONG&gt;intck('month',testdate1,testdate2)&amp;lt;6&lt;/STRONG&gt; as indicator&lt;BR /&gt;from have1 a, have2(rename=(testdate1=testdate2)) b&lt;BR /&gt;where a.id=b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425886#M13121</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-08T19:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425893#M13124</link>
      <description>&lt;P&gt;code copied from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;, add a case statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *, case when&amp;nbsp;&lt;STRONG&gt;intck('month',a.testdate1,b.testdate2)&amp;lt;6&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;then 1 else 0 end as indicatior&lt;/SPAN&gt;&lt;BR /&gt;from have1 a, have2 b&lt;BR /&gt;where a.id=b.id;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 20:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425893#M13124</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-08T20:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425894#M13125</link>
      <description>&lt;P&gt;Thanks for your help! It doesn't work. Testdate1 and testdate2 are not in the same data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 20:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425894#M13125</guid>
      <dc:creator>newbe</dc:creator>
      <dc:date>2018-01-08T20:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425897#M13126</link>
      <description>&lt;P&gt;Thanks for your input! Problem is solved.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 20:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425897#M13126</guid>
      <dc:creator>newbe</dc:creator>
      <dc:date>2018-01-08T20:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: conditional merge of two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425916#M13129</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185451"&gt;@newbe&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your input! Problem is solved.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185451"&gt;@newbe&lt;/a&gt;&amp;nbsp;Please mark the appropriate solution or post the solution you found in the end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 21:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/conditional-merge-of-two-data-sets/m-p/425916#M13129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-08T21:14:02Z</dc:date>
    </item>
  </channel>
</rss>

