<?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: intersecting one dataset based on second dataset in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292185#M311727</link>
    <description>&lt;P&gt;Hi nikhil,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the following additions to your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data merged_data;
    merge primary_data &lt;STRONG&gt;(in=a)&lt;/STRONG&gt; selection &lt;STRONG&gt;(in=b)&lt;/STRONG&gt;;
    by Id;&lt;BR /&gt;    &lt;STRONG&gt;if b;&lt;/STRONG&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this works!&lt;/P&gt;
&lt;P&gt;Kenny&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2016 14:04:05 GMT</pubDate>
    <dc:creator>kewong</dc:creator>
    <dc:date>2016-08-17T14:04:05Z</dc:date>
    <item>
      <title>intersecting one dataset based on second dataset in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292174#M311726</link>
      <description>&lt;P&gt;I have a dataset called '&lt;STRONG&gt;primary_data&lt;/STRONG&gt;' which looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Obs  Id     Month   Name    Salary
1   10006   JAN1926 name1   3273
2   10006   FEB1926 name1   7143
3   10007   JAN1926 name2   4274
4   10008   JAN1926 name3   2591
5   10008   FEB1926 name3   2394
6   10009   JAN1926 name4   4416
.
.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I have another dataset called '&lt;STRONG&gt;selection&lt;/STRONG&gt;' which looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Obs Id
1   10006
2   10008
.
.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note: &lt;STRONG&gt;Id&lt;/STRONG&gt;s are unique in '&lt;STRONG&gt;selection&lt;/STRONG&gt;' dataset&lt;/P&gt;&lt;P&gt;I need to take a subset of &lt;STRONG&gt;primary_data&lt;/STRONG&gt; where the &lt;STRONG&gt;Id&lt;/STRONG&gt;s are taken from '&lt;STRONG&gt;selection&lt;/STRONG&gt;' dataset. I tried merge but I am getting the whole &lt;STRONG&gt;primary_data&lt;/STRONG&gt; as my output.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data merged_data;
    merge primary_data selection;
    by Id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In my example above, I would like &lt;STRONG&gt;merged_data&lt;/STRONG&gt; to have entries corresponding to &lt;STRONG&gt;Id&lt;/STRONG&gt;s: 10006 and 10008 but not from Ids 10007 and 10009. That is, &lt;STRONG&gt;merged_data&lt;/STRONG&gt; should look like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Obs  Id     Month   Name    Salary
1   10006   JAN1926 name1   3273
2   10006   FEB1926 name1   7143
3   10008   JAN1926 name3   2591
4   10008   FEB1926 name3   2394
.
.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I do not understand, what am I doing wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 13:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292174#M311726</guid>
      <dc:creator>nikhil141088</dc:creator>
      <dc:date>2016-08-17T13:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: intersecting one dataset based on second dataset in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292185#M311727</link>
      <description>&lt;P&gt;Hi nikhil,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the following additions to your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data merged_data;
    merge primary_data &lt;STRONG&gt;(in=a)&lt;/STRONG&gt; selection &lt;STRONG&gt;(in=b)&lt;/STRONG&gt;;
    by Id;&lt;BR /&gt;    &lt;STRONG&gt;if b;&lt;/STRONG&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this works!&lt;/P&gt;
&lt;P&gt;Kenny&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292185#M311727</guid>
      <dc:creator>kewong</dc:creator>
      <dc:date>2016-08-17T14:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: intersecting one dataset based on second dataset in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292192#M311728</link>
      <description>&lt;P&gt;Subquery:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  select *
  from   PRIMARY_DATA
  where  ID in (select ID from SELECTION);
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292192#M311728</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-17T14:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: intersecting one dataset based on second dataset in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292194#M311729</link>
      <description>&lt;P&gt;Thanks kenny, this works perfectly.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292194#M311729</guid>
      <dc:creator>nikhil141088</dc:creator>
      <dc:date>2016-08-17T14:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: intersecting one dataset based on second dataset in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292195#M311730</link>
      <description>Thanks KW9, it gives the data as desired.</description>
      <pubDate>Wed, 17 Aug 2016 14:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intersecting-one-dataset-based-on-second-dataset-in-sas/m-p/292195#M311730</guid>
      <dc:creator>nikhil141088</dc:creator>
      <dc:date>2016-08-17T14:20:48Z</dc:date>
    </item>
  </channel>
</rss>

