<?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: Help with merging in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128223#M35050</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The one thing I can think is using INDSNAME= option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.i07; &lt;/P&gt;&lt;P&gt;&amp;nbsp; set hw.i0: indsname=dsn;&lt;/P&gt;&lt;P&gt; name=scan(dsn,-1,'.');&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jul 2013 01:12:12 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2013-07-08T01:12:12Z</dc:date>
    <item>
      <title>Help with merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128222#M35049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 8 different data set, 4 quarter data set from individual level and 4 quarter data set from household level. I would like to combine all these data set into one. Previously I'm using this code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*For Individual&lt;/P&gt;&lt;P&gt;data work.i07; &lt;/P&gt;&lt;P&gt;&amp;nbsp; set hw.i071(in=m071) hw.i072(in=m072) hw.i073(in=m073) hw.i074(in=m074);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if m071=1 then qtr=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if m072=1 then qtr=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if m073=1 then qtr=3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if m074=1 then qtr=4;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*For Household &lt;/P&gt;&lt;P&gt;data work.f07; &lt;/P&gt;&lt;P&gt;&amp;nbsp; set hw.F071(in=f071) hw.F072(in=f072) hw.F073(in=f073) hw.F074(in=f074);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if f071=1 then qtr=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if f072=1 then qtr=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if f073=1 then qtr=3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if f074=1 then qtr=4;\&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Merging both &lt;/P&gt;&lt;P&gt;data hw.all07; &lt;/P&gt;&lt;P&gt;&amp;nbsp; merge work.f07&lt;/P&gt;&lt;P&gt; work.i07p;&lt;/P&gt;&lt;P&gt;by CU_ID;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That code works, but I wonder if there is any simple code to do it. Perhaps using single data step instead using multiple step. Thank you. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Jul 2013 21:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128222#M35049</guid>
      <dc:creator>inuman</dc:creator>
      <dc:date>2013-07-07T21:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128223#M35050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The one thing I can think is using INDSNAME= option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.i07; &lt;/P&gt;&lt;P&gt;&amp;nbsp; set hw.i0: indsname=dsn;&lt;/P&gt;&lt;P&gt; name=scan(dsn,-1,'.');&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 01:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128223#M35050</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-08T01:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128224#M35051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;Hi &lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="-1" data-externalid="" data-presence="null" data-userid="818111" data-username="inuman" href="https://communities.sas.com/people/inuman" id="jive-81811173734471818786803" style="padding: 0 3px 0 0; font-weight: inherit; font-style: inherit; font-size: 1.1em; font-family: inherit; color: #0e66ba;"&gt;inuman,&lt;/A&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is important to understand that simpler code doesn't necessarily mean better code.&amp;nbsp; You need to measure how efficient the code is to run and also take into account how easy the code is to interpret by other users.&amp;nbsp; I have created some code that is very efficient from a keystroke perspective, but was either inefficient to run when bench marked against other methods or unreadable by my colleagues. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't really understand why you are creating the variable QTR twice.&amp;nbsp; If you are merging the datasets with QTR in both, then the "F" datasets QTR variable results will be overwritten with the results from the QTR variable in the "I" dataset once merged.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Keeping this in mind you could do the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dual Set Merge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA FDATA (INDEX = (CU_ID));&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET HW.F071 HW.F072&amp;nbsp; HW.F073&amp;nbsp; HW.F074;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA WORK.I07;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET HW.I071 (IN = M071) HW.I072 (IN = M072) HW.I073 (IN = M073) HW.I074 (IN = M074);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF M071=1 THEN QTR=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ELSE IF M072=1 THEN QTR=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ELSE IF M073=1 THEN QTR=3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ELSE IF M074=1 THEN QTR=4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET&amp;nbsp; FDATA KEY = CU_ID;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As suggested by KSharp you could use INDSNAME, however this was only implemented in version 9.2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SQL Merge;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE WORK.I07V2 AS&lt;/P&gt;&lt;P&gt;SELECT * FROM&lt;/P&gt;&lt;P&gt;(SELECT *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 AS QTR FROM HW.I071&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT * ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 AS QTR FROM HW.I072&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT * ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 AS QTR FROM HW.I073&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT * ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4 AS QTR FROM HW.I074) AS I,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(SELECT * FROM HW.F071&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT * FROM HW.F072&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT * FROM HW.F073&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT * FROM HW.F074) AS F&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHERE I.CU_ID = F.CU_ID&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Be careful when using SQL for merges as a Cartesian product is produced and then trimmed to meet the conditions of the where statement, which can be quite inefficient.&amp;nbsp; SAS datasteps are highly optimized and should be used in most instances, however SQL certainly has it's uses and shouldn't be entirely over looked.&amp;nbsp; Once again it comes down to benchmarking and testing to ensure that you have the most efficient code for any given situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have made a few assumptions about the structure of your data in the above example, but the basics are here for you to build upon.&amp;nbsp; You could also perform a hash lookup, but I find these confusing for other users to read, therefore I use them sparingly and only when entirely necessary from a performance standpoint - usually when you have a very small dataset you want to merge against a very large one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this is useful.&amp;nbsp; If not, please send a sample of the data you are using and I will attempt to help further.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 03:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128224#M35051</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-08T03:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128225#M35052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for both of your answer (Ksharp and Scott_Mitchell). I'll try your suggestion and see which one is the most efficient way. I'll be back here if I find any unresolved issues. Thank you once again. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wisnu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 04:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-merging/m-p/128225#M35052</guid>
      <dc:creator>inuman</dc:creator>
      <dc:date>2013-07-08T04:37:23Z</dc:date>
    </item>
  </channel>
</rss>

