<?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 datasets with repeated variables in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284248#M803</link>
    <description>&lt;P&gt;Hello, I'm using SAS University edition / SAS studio.&lt;/P&gt;&lt;P&gt;I have two datasets with three variables item ID; quantity and price. The first data set has item ID and a unique quantity for that item. The second&amp;nbsp;data set has item ID and price for that item - but the item ID and (same) price appear several repeated times. &amp;nbsp;&lt;/P&gt;&lt;P&gt;I just want a merged data set that has:&amp;nbsp;item ID, quantity and one (same) price as the columns. How do I do this?&lt;/P&gt;&lt;P&gt;For example, see the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Create sample data */&lt;BR /&gt;data one;&lt;BR /&gt;&amp;nbsp;input id $ quantity $;&lt;BR /&gt;&amp;nbsp;datalines;&lt;BR /&gt;Item_a 4&lt;BR /&gt;Item_b 3&lt;BR /&gt;Item_c 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;&amp;nbsp;input id $ price $;&lt;BR /&gt;&amp;nbsp;datalines;&lt;BR /&gt;Item_a 1.10&lt;BR /&gt;Item_a 1.10&lt;BR /&gt;Item_b 2.35&lt;BR /&gt;Item_b 2.35&lt;BR /&gt;Item_c 5.50&lt;BR /&gt;Item_c 5.50&lt;BR /&gt;Item_c 5.50;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data both;&lt;BR /&gt;&amp;nbsp;merge one (in=in1) two (in=in2);&lt;BR /&gt;&amp;nbsp;by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;if in1=1 and in2=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=both;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jul 2016 05:55:50 GMT</pubDate>
    <dc:creator>Phil_from_PGA</dc:creator>
    <dc:date>2016-07-14T05:55:50Z</dc:date>
    <item>
      <title>Merging datasets with repeated variables</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284248#M803</link>
      <description>&lt;P&gt;Hello, I'm using SAS University edition / SAS studio.&lt;/P&gt;&lt;P&gt;I have two datasets with three variables item ID; quantity and price. The first data set has item ID and a unique quantity for that item. The second&amp;nbsp;data set has item ID and price for that item - but the item ID and (same) price appear several repeated times. &amp;nbsp;&lt;/P&gt;&lt;P&gt;I just want a merged data set that has:&amp;nbsp;item ID, quantity and one (same) price as the columns. How do I do this?&lt;/P&gt;&lt;P&gt;For example, see the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Create sample data */&lt;BR /&gt;data one;&lt;BR /&gt;&amp;nbsp;input id $ quantity $;&lt;BR /&gt;&amp;nbsp;datalines;&lt;BR /&gt;Item_a 4&lt;BR /&gt;Item_b 3&lt;BR /&gt;Item_c 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;&amp;nbsp;input id $ price $;&lt;BR /&gt;&amp;nbsp;datalines;&lt;BR /&gt;Item_a 1.10&lt;BR /&gt;Item_a 1.10&lt;BR /&gt;Item_b 2.35&lt;BR /&gt;Item_b 2.35&lt;BR /&gt;Item_c 5.50&lt;BR /&gt;Item_c 5.50&lt;BR /&gt;Item_c 5.50;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data both;&lt;BR /&gt;&amp;nbsp;merge one (in=in1) two (in=in2);&lt;BR /&gt;&amp;nbsp;by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;if in1=1 and in2=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=both;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 05:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284248#M803</guid>
      <dc:creator>Phil_from_PGA</dc:creator>
      <dc:date>2016-07-14T05:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with repeated variables</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284249#M804</link>
      <description>&lt;P&gt;Why does the second data set have duplicates? I would remove the duplicates and then merge. Your data step code will work. You can remove duplicates with proc sort and noduprecs or nodupkey.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 06:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284249#M804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-14T06:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with repeated variables</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284255#M805</link>
      <description>Thanks - that worked well.&lt;BR /&gt;</description>
      <pubDate>Thu, 14 Jul 2016 07:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-datasets-with-repeated-variables/m-p/284255#M805</guid>
      <dc:creator>Phil_from_PGA</dc:creator>
      <dc:date>2016-07-14T07:21:28Z</dc:date>
    </item>
  </channel>
</rss>

