<?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 How to merge datasets with duplicate variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/707991#M217478</link>
    <description>&lt;P&gt;Hi everyone, I'm a bit new to SAS and I need a bit of help merging two datasets.&lt;/P&gt;&lt;P&gt;My first data set has a ticker symbol and multiple years for each ticker. Example: lib1.tickerdata&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ticker&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;Year&lt;/U&gt;&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2001&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2002&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001&lt;/P&gt;&lt;P&gt;My second dataset holds an ID number for each ticker. Example: lib1.IDdata&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ticker&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;U&gt;ID number&lt;/U&gt;&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; 0002&lt;/P&gt;&lt;P&gt;I would like to merge the two so that it looks like:&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ticker&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;Year&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;U&gt;ID Number&lt;/U&gt;&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2001&amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2002&amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&amp;nbsp; &amp;nbsp; &amp;nbsp;0002&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001&amp;nbsp; &amp;nbsp; &amp;nbsp;0002&lt;/P&gt;&lt;P&gt;How can I perform this task? Essentially, I'd like to keep lib1.Tickerdata the same and add a new variable, ID number, based on the ticker. Similar to what a VLOOKUP could do on excel. I used this code, but for some reason it gives me one extra observation than the original set (lib1.tickerdata). SAS also gives me the note: MERGE statement has more than one data set with repeats of BY values. Is this note okay given the fact that I'd like the keep the duplicates in lib1.tickerdata?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib1.merged
merge lib1.tickerdata (in=in1)
lib1.IDdata (in=in2)
by TICKER;
if in1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help would be greatly appreciated! Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Dec 2020 21:07:15 GMT</pubDate>
    <dc:creator>lb16fa</dc:creator>
    <dc:date>2020-12-23T21:07:15Z</dc:date>
    <item>
      <title>How to merge datasets with duplicate variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/707991#M217478</link>
      <description>&lt;P&gt;Hi everyone, I'm a bit new to SAS and I need a bit of help merging two datasets.&lt;/P&gt;&lt;P&gt;My first data set has a ticker symbol and multiple years for each ticker. Example: lib1.tickerdata&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ticker&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;Year&lt;/U&gt;&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2001&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2002&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001&lt;/P&gt;&lt;P&gt;My second dataset holds an ID number for each ticker. Example: lib1.IDdata&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ticker&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;U&gt;ID number&lt;/U&gt;&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; 0002&lt;/P&gt;&lt;P&gt;I would like to merge the two so that it looks like:&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ticker&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;Year&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;U&gt;ID Number&lt;/U&gt;&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2001&amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;APPL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2002&amp;nbsp; &amp;nbsp; &amp;nbsp;0001&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&amp;nbsp; &amp;nbsp; &amp;nbsp;0002&lt;/P&gt;&lt;P&gt;MSFT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001&amp;nbsp; &amp;nbsp; &amp;nbsp;0002&lt;/P&gt;&lt;P&gt;How can I perform this task? Essentially, I'd like to keep lib1.Tickerdata the same and add a new variable, ID number, based on the ticker. Similar to what a VLOOKUP could do on excel. I used this code, but for some reason it gives me one extra observation than the original set (lib1.tickerdata). SAS also gives me the note: MERGE statement has more than one data set with repeats of BY values. Is this note okay given the fact that I'd like the keep the duplicates in lib1.tickerdata?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib1.merged
merge lib1.tickerdata (in=in1)
lib1.IDdata (in=in2)
by TICKER;
if in1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help would be greatly appreciated! Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 21:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/707991#M217478</guid>
      <dc:creator>lb16fa</dc:creator>
      <dc:date>2020-12-23T21:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge datasets with duplicate variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708000#M217483</link>
      <description>&lt;P&gt;The SAS note indicates that you have duplicate ticker values in your second dataset. Is this what you expect? If so how do you want to handle the duplicates? If not how do you want to de-duplicate?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 21:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708000#M217483</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-23T21:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge datasets with duplicate variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708001#M217484</link>
      <description>&lt;P&gt;Your IDDATA dataset seems to have multiple entries for some tickers. Check if these unexpected duplicates are valid, and decide how to deal with them.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 21:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708001#M217484</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-23T21:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge datasets with duplicate variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708002#M217485</link>
      <description>&lt;P&gt;Your code looks fine.&amp;nbsp; But the message is saying that there is more&amp;nbsp; than one observation in the lookup table (IDDATA) for at least one value of TICKER that also has multiple observations for that value of TICKER.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all of the repeating records in IDDATA have the same value of ID_NUMBER it will not matter.&amp;nbsp; If they don't then you need to decide how to pick just one.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 21:21:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708002#M217485</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-23T21:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge datasets with duplicate variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708008#M217488</link>
      <description>&lt;P&gt;That makes sense! I'll take a look at the ID data set to find the repeating records.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 21:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-datasets-with-duplicate-variables/m-p/708008#M217488</guid>
      <dc:creator>lb16fa</dc:creator>
      <dc:date>2020-12-23T21:29:23Z</dc:date>
    </item>
  </channel>
</rss>

