<?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: Merging Information From One Dataset To Another But Retaining Original Copies in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/722010#M223826</link>
    <description>I'm not sure why, but my BASE file is still the same when I proc print it, there are no new variables attached....</description>
    <pubDate>Thu, 25 Feb 2021 22:02:35 GMT</pubDate>
    <dc:creator>mkimmi</dc:creator>
    <dc:date>2021-02-25T22:02:35Z</dc:date>
    <item>
      <title>Merging Information From One Dataset To Another But Retaining Original Copies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/721581#M223682</link>
      <description>&lt;P&gt;Not sure if "merge" is the function I ultimately want, but it's what I tried....and flopped lol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have two data sets:&lt;/P&gt;&lt;P&gt;1. Base (goes on much longer than this)&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;ZIPCODE&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;YEAR&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;D&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt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gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;n&lt;/TD&gt;&lt;TD&gt;q&lt;/TD&gt;&lt;TD&gt;11011&lt;/TD&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;o&lt;/TD&gt;&lt;TD&gt;r&lt;/TD&gt;&lt;TD&gt;11102&lt;/TD&gt;&lt;TD&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;s&lt;/TD&gt;&lt;TD&gt;t&lt;/TD&gt;&lt;TD&gt;90384&lt;/TD&gt;&lt;TD&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;u&lt;/TD&gt;&lt;TD&gt;v&lt;/TD&gt;&lt;TD&gt;10090&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of them have say two variables in common: Name is correct, format is the same, information is the same. (Zipcode and Year)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each observation in Base dataset, I want to look up on the References table and find the matching Zipcode and Year. If and only if there is a match, then add the variables from References table to the Base dataset:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;ZIPCODE&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;YEAR&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;D&lt;/STRONG&gt;&lt;/TD&gt;&lt;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ode and Year in Base dataset (11011, 2015) even though other variables have different information, so I want to be able to append the information while retaining that information in the References dataset for later observations that have the same zipcode/year.&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(2)&lt;/STRONG&gt; some Zipcode and Year in Reference dataset may not be present in Base dataset (e.g. 90384, 2013 and 10090, 2016), so I don't want these to merge into Base dataset with empty cells for other variables (since there are no observations in Base dataset with said zip code and year).&lt;/P&gt;&lt;P&gt;These are two issues I've been running into, and not sure how to solve...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 14:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/721581#M223682</guid>
      <dc:creator>mkimmi</dc:creator>
      <dc:date>2021-02-24T14:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Information From One Dataset To Another But Retaining Original Copies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/721589#M223684</link>
      <description>&lt;P&gt;You mentioned "&lt;EM&gt;&lt;SPAN&gt;Both of them have say two variables in common:&lt;/SPAN&gt;&lt;/EM&gt;". The only common variables I see are&amp;nbsp;&lt;STRONG&gt;zipcode&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;year&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;You mentioned "name is correct" - there is no variable named NAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general you can use sql to join data from the two tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select b.*   /* all BASE variables */
             ,r.&amp;lt;var1&amp;gt;
             .r.&amp;lt;var2&amp;gt;
            /* add as many REFERENCE variables as need */
   from BASE as b
   left join REFERENCE as r
   on (b.&amp;lt;common var-1&amp;gt; = r.&amp;lt;common var-1&amp;gt; and
         b.&amp;lt;common var-2&amp;gt; = r.&amp;lt;common var-2&amp;gt;
       /* compete any more conditions if need */
       )
      sort by b.&amp;lt;common var-1&amp;gt; , b.&amp;lt;common var-2&amp;gt;;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 15:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/721589#M223684</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-24T15:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Information From One Dataset To Another But Retaining Original Copies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/721602#M223688</link>
      <description>Quick clarification: "Both of them" -- both datasets of two common variables, whose names are correct -- as in ZIPCODE is ZIPCODE and YEAR is YEAR in both datasets&lt;BR /&gt;&lt;BR /&gt;Thanks so much--will try this!! I'm finally getting a hang of proc sql and macros</description>
      <pubDate>Wed, 24 Feb 2021 15:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/721602#M223688</guid>
      <dc:creator>mkimmi</dc:creator>
      <dc:date>2021-02-24T15:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Information From One Dataset To Another But Retaining Original Copies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/722010#M223826</link>
      <description>I'm not sure why, but my BASE file is still the same when I proc print it, there are no new variables attached....</description>
      <pubDate>Thu, 25 Feb 2021 22:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/722010#M223826</guid>
      <dc:creator>mkimmi</dc:creator>
      <dc:date>2021-02-25T22:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Information From One Dataset To Another But Retaining Original Copies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/722022#M223833</link>
      <description>&lt;P&gt;Please post the exact code you run, or even better the full log of the run showing the code and the messages.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 00:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Information-From-One-Dataset-To-Another-But-Retaining/m-p/722022#M223833</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-26T00:55:17Z</dc:date>
    </item>
  </channel>
</rss>

