<?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 data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117418#M24216</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I would like to merge two data sets with the intent of just adding one column (Denominator) to the "s6Freq72Numerator" data set. I thought I was able to easily do this in the past, but maybe not. The code I thought would be successful in doing this is below. However, when I use this, the resulting data set is not sorted by exitMonthCategory and and there are missing records from "s6Freq72Numerator".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am attaching a spreadsheet that has an example of the data from the "s6Freq72Numerator" and "s6Freq72Denominator" data sets and what I was intending as the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If anyone has any ideas, please let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=s6Freq72Numerator;&lt;/P&gt;&lt;P&gt; by cnty_name startyear exitMonthCategory;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; proc sort data=s6Freq72Denominator;&lt;/P&gt;&lt;P&gt; by cnty_name startyear exitMonthCategory;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; data s6Final72;&lt;/P&gt;&lt;P&gt; merge s6Freq72Numerator s6Freq72Denominator;&lt;/P&gt;&lt;P&gt; by cnty_name startyear;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Feb 2013 15:03:28 GMT</pubDate>
    <dc:creator>Paul_NYS</dc:creator>
    <dc:date>2013-02-21T15:03:28Z</dc:date>
    <item>
      <title>Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117418#M24216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I would like to merge two data sets with the intent of just adding one column (Denominator) to the "s6Freq72Numerator" data set. I thought I was able to easily do this in the past, but maybe not. The code I thought would be successful in doing this is below. However, when I use this, the resulting data set is not sorted by exitMonthCategory and and there are missing records from "s6Freq72Numerator".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am attaching a spreadsheet that has an example of the data from the "s6Freq72Numerator" and "s6Freq72Denominator" data sets and what I was intending as the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If anyone has any ideas, please let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=s6Freq72Numerator;&lt;/P&gt;&lt;P&gt; by cnty_name startyear exitMonthCategory;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; proc sort data=s6Freq72Denominator;&lt;/P&gt;&lt;P&gt; by cnty_name startyear exitMonthCategory;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; data s6Final72;&lt;/P&gt;&lt;P&gt; merge s6Freq72Numerator s6Freq72Denominator;&lt;/P&gt;&lt;P&gt; by cnty_name startyear;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 15:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117418#M24216</guid>
      <dc:creator>Paul_NYS</dc:creator>
      <dc:date>2013-02-21T15:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117419#M24217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Paul,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without looking at your data, why don't you just try adding exitMonthCategory at the end of the merge by statement?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 16:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117419#M24217</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-02-21T16:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117420#M24218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since both of your input data sets are sorted by cnty_name startyear and exitMonthCategory the output of the merged data set is sorted on the same variables. If you need the output sorted by exitMonthCategory you need another sort after the merge.&lt;/P&gt;&lt;P&gt;You probably have missing values for your numerator variable because the combination of the sort variables didn't exist in the numerator data set but did exist in the denominator set. Or you have multiples.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternative approach might be&lt;/P&gt;&lt;P&gt;(This does not require sorting the data first)&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table s6Final72 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.*, b.s6Freq72Numerator&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; froms 6Freq72Denominator as a left joint s6Freq72Numerator as b on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.cnty_name=b.cnty_name and a.startyear=b.startyear and a.exitMonthCategory=b.exitMonthCategory&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by a.exitMonthCategory;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 16:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117420#M24218</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-02-21T16:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117421#M24219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;Below code will give you the desired output, exactly matching to your Expected results -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;data s6Final72;&lt;/P&gt;&lt;P&gt;merge s6Freq72Denominator s6Freq72Numerator(in=a) ;&lt;/P&gt;&lt;P&gt;by cnty_name startyear;&lt;BR /&gt;if a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 16:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117421#M24219</guid>
      <dc:creator>kij23</dc:creator>
      <dc:date>2013-02-21T16:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117422#M24220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Art&lt;/P&gt;&lt;P&gt;Because it will only print the Denominator to the one value that matches on the exitMonthCategory value. There are other values of exitMonthCategory in s6Freq72Numerator that will be blank. I tried that already actually.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 16:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117422#M24220</guid>
      <dc:creator>Paul_NYS</dc:creator>
      <dc:date>2013-02-21T16:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117423#M24221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kij&lt;/P&gt;&lt;P&gt;I actually tried that and it comes close, however for some reason the '6' value of exitMonthCategory in s6Freq72Numerator gets renamed to the exitMonthCategory in s6Freq72Denominator and the CumulativeNumber is set to the Denominator in s6Freq72Denominator for the given county/year combo. If I can't find any proper way to do this, then I was going to do what you have below and rename all the '6' values back to their correct records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 16:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117423#M24221</guid>
      <dc:creator>Paul_NYS</dc:creator>
      <dc:date>2013-02-21T16:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117424#M24222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ballard&lt;/P&gt;&lt;P&gt;I didn't think of using proc sql, but will give it a shot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 16:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117424#M24222</guid>
      <dc:creator>Paul_NYS</dc:creator>
      <dc:date>2013-02-21T16:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117425#M24223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Paul,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following worked for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data s6Final72;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge&amp;nbsp; s6Freq72Denominator (drop=exitMonthCategory) s6Freq72Numerator (in=a);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by cnty_name startyear;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if a;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 17:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117425#M24223</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-02-21T17:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117426#M24224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The important feature of this and kij23's reply is that the denominator file precedes the numerator file. When that's the case, the drop= option should not be necessary, I think ... but it's always cleaner.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 17:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117426#M24224</guid>
      <dc:creator>DanWALDO</dc:creator>
      <dc:date>2013-02-21T17:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117427#M24225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Art&lt;/P&gt;&lt;P&gt;The second one worked perfectly. Thanks a lot. I guess I originally missed the drop statement then.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 17:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117427#M24225</guid>
      <dc:creator>Paul_NYS</dc:creator>
      <dc:date>2013-02-21T17:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117428#M24226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Paul,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Dan pointed out, the drop statement really wasn't even necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem you had was (1) using the denominator file as the 2nd rather than the first file and (2) not using an in= option to exclude irrelevant records from the denominator file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 18:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-sets/m-p/117428#M24226</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-02-21T18:50:44Z</dc:date>
    </item>
  </channel>
</rss>

