<?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: SAS merge on different variables based on availability in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/399156#M96646</link>
    <description>&lt;P&gt;Around a couple million observations.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2017 13:22:59 GMT</pubDate>
    <dc:creator>Shirin</dc:creator>
    <dc:date>2017-09-27T13:22:59Z</dc:date>
    <item>
      <title>SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398147#M96260</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm tryingh to do a SAS merge, based on two different variables.&lt;/P&gt;
&lt;P&gt;If variable A is not blank then merge on variable A, and if it's blank, then merge on variable B instead.&lt;/P&gt;
&lt;P&gt;Is this possible, or do I have to break up the file based on availability of variable A and do two different merges?&lt;/P&gt;
&lt;P&gt;Any healp would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398147#M96260</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-09-22T15:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398150#M96262</link>
      <description>&lt;P&gt;I think that you need to provide examples of your two datasets (if you have LOTS of other variables then only a couple please if they aren't involved in the problem) and what you expect the result to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The are a number of ways to combine datasets and a concrete example will provide much better responses instead of us guessing as to the actual desired output.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398150#M96262</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-22T15:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398155#M96264</link>
      <description>&lt;P&gt;Do the join in SQL and you can have a condition on one side, or you can pre-create the variable using the COALESCE(C) function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*assuming a character variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge_var = coalesceC(a, b);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or via SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from table1 as t1
join table2 as t2
on coalesce(t1.A, t1.B) = t2.A

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398155#M96264</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-22T15:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398221#M96292</link>
      <description>&lt;P&gt;I have a very huge dataset, both vertically and horizontally... But I think here is a simple way to demonstrate what I have and what I want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; test1;&lt;/P&gt;
&lt;P&gt;input Name ID1 ID2 othervar1 $ ;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;Sharon 185 18 fge&lt;/P&gt;
&lt;P&gt;James 257 25 sdfh&lt;/P&gt;
&lt;P&gt;Mike 253 25 awer&lt;/P&gt;
&lt;P&gt;Matt 814 81 sduifh&lt;/P&gt;
&lt;P&gt;John 567 56 fhjuk&lt;/P&gt;
&lt;P&gt;Sherri 453 45 uih&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; correspondence;&lt;/P&gt;
&lt;P&gt;input ID1 ID2 othervar2 $;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;185 18 rtr&lt;/P&gt;
&lt;P&gt;. 25 sd&lt;/P&gt;
&lt;P&gt;814 81 we&lt;/P&gt;
&lt;P&gt;567 56 hj&lt;/P&gt;
&lt;P&gt;453 45 qw&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want:&lt;/P&gt;
&lt;P&gt;Name ID1 ID2 othervar1 othervar2 ;&lt;/P&gt;
&lt;P&gt;Sharon &lt;STRONG&gt;185&lt;/STRONG&gt; &lt;STRONG&gt;18&lt;/STRONG&gt; fge rtr&lt;/P&gt;
&lt;P&gt;James &lt;STRONG&gt;257&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt; sdfh sd&lt;/P&gt;
&lt;P&gt;Mike &lt;STRONG&gt;253&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt; awer sd&lt;/P&gt;
&lt;P&gt;Matt &lt;STRONG&gt;814&lt;/STRONG&gt; &lt;STRONG&gt;81&lt;/STRONG&gt; sduifh we&lt;/P&gt;
&lt;P&gt;John &lt;STRONG&gt;567&lt;/STRONG&gt; &lt;STRONG&gt;56&lt;/STRONG&gt; fhjuk hj&lt;/P&gt;
&lt;P&gt;Sherri &lt;STRONG&gt;453&lt;/STRONG&gt; &lt;STRONG&gt;45&lt;/STRONG&gt; uih qw&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 20:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398221#M96292</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-09-22T20:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398222#M96293</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46496"&gt;@Shirin&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a very huge dataset, both vertically and horizontally... But I think here is a simple way to demonstrate what I have and what I want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What's your definition of 'huge'? 100,000 or 1 trillion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 20:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398222#M96293</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-22T20:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398231#M96301</link>
      <description>&lt;P&gt;For your example data a merge&amp;nbsp;(or join)&amp;nbsp;on ID2 works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test1;
input Name $ ID1 ID2 othervar1 $ ;
datalines;
Sharon 185 18 fge
James 257 25 sdfh
Mike 253 25 awer
Matt 814 81 sduifh
John 567 56 fhjuk
Sherri 453 45 uih
;
run;
 
data correspondence;
input ID1 ID2 othervar2 $;
datalines;
185 18 rtr
. 25 sd
814 81 we
567 56 hj
453 45 qw
;
run;

proc sort data=test1;
   by id2;
run;
proc sort data=correspondence;
   by id2;
run;

data want;
   merge correspondence test1  ;
   by id2;
run;


&lt;/PRE&gt;
&lt;P&gt;Note addition of $ so name gets read as character. Order of variables and records is different but the values are the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is you example data incomplete to exercise all the options required?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 21:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/398231#M96301</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-22T21:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/399156#M96646</link>
      <description>&lt;P&gt;Around a couple million observations.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/399156#M96646</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-09-27T13:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge on different variables based on availability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/399168#M96651</link>
      <description>&lt;P&gt;Hi Reeza, I didnt know thsi function existed, thanks!&lt;/P&gt;
&lt;P&gt;So I'm saying join it on:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; from t1: A if exists and B if A doesnt exist&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; from t2: on A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But how do I say to join it from t2, on the same variable as in t1?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-on-different-variables-based-on-availability/m-p/399168#M96651</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-09-27T13:57:14Z</dc:date>
    </item>
  </channel>
</rss>

