<?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: How to merge if variable contains some matching observations to another variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478706#M286387</link>
    <description>&lt;P&gt;on a substr = b substr would result in cartesian. What results do you want in your output?&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2018 16:26:47 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-07-17T16:26:47Z</dc:date>
    <item>
      <title>How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478704#M286386</link>
      <description>&lt;P&gt;I have ID1 and ID2 as two variables in different datasets.&lt;/P&gt;&lt;P&gt;Small example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1&lt;/P&gt;&lt;P&gt;A01&lt;/P&gt;&lt;P&gt;A02&lt;/P&gt;&lt;P&gt;A03&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID2&lt;/P&gt;&lt;P&gt;101&lt;/P&gt;&lt;P&gt;102&lt;/P&gt;&lt;P&gt;103&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I merge based on the right-most two characters?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have explored possibilities of PROC SQL but was unable to find a simple solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478704#M286386</guid>
      <dc:creator>Ramsha</dc:creator>
      <dc:date>2018-07-17T16:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478706#M286387</link>
      <description>&lt;P&gt;on a substr = b substr would result in cartesian. What results do you want in your output?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478706#M286387</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-17T16:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478708#M286388</link>
      <description>&lt;P&gt;easy way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input ID1 $;
k=substr(id1,2);
cards;
A01
A02
A03
;
 
data two;
input ID2 $;
k=substr(id2,2);
cards;
101
102
103
;
data want;
merge one two;
by k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478708#M286388</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-17T16:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478709#M286389</link>
      <description>&lt;P&gt;Hello, thanks for your response!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is part of a bigger project. Essentially, I am combining two excel worksheets. I am merging them based off of one column which I simplified to ID1 and ID2 in this example. Problem is, ID2 only contains some of the string of ID1. However I need to do data matching based on this variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478709#M286389</guid>
      <dc:creator>Ramsha</dc:creator>
      <dc:date>2018-07-17T16:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478711#M286390</link>
      <description>&lt;P&gt;Please post a best representative and comprehensive sample that you can, so that it's easy for everybody. Then explain your requirement. I am sure many would love to offer you the solution you need&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if you are merging excel sheets, You are better off doing that in excel vba rather than SAS in my opinion.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478711#M286390</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-17T16:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478713#M286391</link>
      <description>&lt;P&gt;This does one form of match. Please notice the way to provide example data that code can be tested with. Also I added different length variables to show 1) that the last 2 characters are compared ignoring length and 2) to show an example of what may not be desirable for the match, 37 vs 237, just in case. The JOIN type depends on which records you may want in case of not match from the first set or the second set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.d1;
input ID1 $;
datalines;
A01
A02
A03
AB37
;
run;
 
data work.d2;
input ID2 $;
datalines;
101
102
103
PDQ237
;
run;

proc sql;
   create table work.both as
   select a.id1, b.id2
   from work.d1 as a
        left join
        work.d2 as b
        on substr(a.id1, length(a.id1)-1)=substr(b.id2,length(b.id2)-1) 
   ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478713#M286391</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-17T16:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478714#M286392</link>
      <description>&lt;P&gt;SQL works fine. Assuming both are character&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from table1
left join table2
on substr(id1, 1, 2) = substr(id2, 1, 2)
.....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they're numeric you'll need a slightly different approach but&amp;nbsp;this should give you the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181583"&gt;@Ramsha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have ID1 and ID2 as two variables in different datasets.&lt;/P&gt;
&lt;P&gt;Small example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID1&lt;/P&gt;
&lt;P&gt;A01&lt;/P&gt;
&lt;P&gt;A02&lt;/P&gt;
&lt;P&gt;A03&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID2&lt;/P&gt;
&lt;P&gt;101&lt;/P&gt;
&lt;P&gt;102&lt;/P&gt;
&lt;P&gt;103&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I merge based on the right-most two characters?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have explored possibilities of PROC SQL but was unable to find a simple solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478714#M286392</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-17T16:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge if variable contains some matching observations to another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478717#M286393</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see attached thread that I just posted for more information on the question. Thank you so much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/How-to-merge-excel-data-together-based-on-variable-that-contains/m-p/478716#M58613&amp;nbsp;" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/How-to-merge-excel-data-together-based-on-variable-that-contains/m-p/478716#M58613&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-if-variable-contains-some-matching-observations-to/m-p/478717#M286393</guid>
      <dc:creator>Ramsha</dc:creator>
      <dc:date>2018-07-17T16:49:19Z</dc:date>
    </item>
  </channel>
</rss>

