<?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, retain all observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667312#M79075</link>
    <description>Do you mean remove if _a; ? This does not solve my problem.</description>
    <pubDate>Mon, 06 Jul 2020 22:58:03 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2020-07-06T22:58:03Z</dc:date>
    <item>
      <title>Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667303#M79069</link>
      <description>&lt;P&gt;I was wondering if anyone knows how I can merge two data sets conditionally while also retaining &lt;EM&gt;all &lt;/EM&gt;observations, regardless of whether they merged. I have two data sets, each is unique by year and individ_id_num. Each data set contains multiple years of data (2000-2020), but I only want to merge for the year=2018. I seem to have achieved this with the code below, &lt;STRONG&gt;but&lt;/STRONG&gt; my final data set only contains observations where year=2018. I want to retains &lt;EM&gt;all&lt;/EM&gt; observations (in1) regardless of whether it merged to an observation in the merging data set. Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
    merge have1(where=(year=2018) in=in1) 
               have2(where=(year=2018) in=in2);
    by indiv_id_num;

    if in1;
    
    if in1 and in2 then merge_18=1;
    else merge_18 = 0;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jul 2020 22:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667303#M79069</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-07-06T22:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667306#M79071</link>
      <description>&lt;P&gt;What is wrong with the code you show?&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Jul 2020 22:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667306#M79071</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-06T22:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667307#M79072</link>
      <description>It only retains the 2018 observations in the final data set. I want to retain all years (2000-2020), even though only the 2018 observations have been merged to the second data set.</description>
      <pubDate>Mon, 06 Jul 2020 22:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667307#M79072</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-07-06T22:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667309#M79073</link>
      <description>&lt;P&gt;The modification to the code should be obvious. &lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Jul 2020 22:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667309#M79073</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-06T22:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667310#M79074</link>
      <description>Does the second data set have only 2018 data or other years as well? Do you have a year variable in your data set?&lt;BR /&gt;Can you merge by individ_id_num and Year instead?&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;    merge have1( in=in1) &lt;BR /&gt;               have2(where=(year=2018) in=in2);&lt;BR /&gt;    by indiv_id_num;&lt;BR /&gt;&lt;BR /&gt;    if in1;&lt;BR /&gt;    &lt;BR /&gt;    if in1 and in2 then merge_18=1;&lt;BR /&gt;    else merge_18 = 0;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;    merge have1( in=in1) &lt;BR /&gt;               have2(where=(year=2018) in=in2);&lt;BR /&gt;    by indiv_id_num year;&lt;BR /&gt;&lt;BR /&gt;    if in1;&lt;BR /&gt;    &lt;BR /&gt;    if in1 and in2 then merge_18=1;&lt;BR /&gt;    else merge_18 = 0;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 06 Jul 2020 22:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667310#M79074</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-06T22:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667312#M79075</link>
      <description>Do you mean remove if _a; ? This does not solve my problem.</description>
      <pubDate>Mon, 06 Jul 2020 22:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667312#M79075</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-07-06T22:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667388#M79076</link>
      <description>&lt;P&gt;The where= dataset options prevent any years other than 2018 from processing in your data step, so you need to remove those.&lt;/P&gt;
&lt;P&gt;You will need to merge by indiv_id_num and year, and set your final variable only when year = 2018.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To provide you with (tested) code, we need examples for have1 and have2, and the expected outcome from those examples. Provide those examples as data steps with datalines, so we can easily create your datasets in our environments.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 09:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667388#M79076</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-07T09:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merge, retain all observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667392#M79077</link>
      <description>&lt;P&gt;The code you showed uses this fragment of code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;have1(where=(year=2018))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to change the code to use all years, you modify the above code to ...&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 10:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-merge-retain-all-observations/m-p/667392#M79077</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-07T10:31:53Z</dc:date>
    </item>
  </channel>
</rss>

