<?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: Join on substring from a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679571#M205210</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp; -&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on substr(a.SUB_S,1,8)=catx('_',scan(b.SUB_S,1,'_'),scan(b.SUB_S,3,'_'));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 26 Aug 2020 18:18:24 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-08-26T18:18:24Z</dc:date>
    <item>
      <title>Join on substring from a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679561#M205206</link>
      <description>&lt;P&gt;I've the two datasets (Have 1, Have 2)&amp;nbsp;which has data as follows. I want to to create a target table based on matching values from 'Have2'. When I say matching values, it doesn't mean all values but only few value from Have 1 with Have 2 to get desired Output. For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have 1 dataset looks like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SUB_S	        ID
2718_AP1	78.76
2718_AP2-A	23.76
2718_AP2-B	23.76
2718_AP3-A	97.09
2718_AP3-C	97.09
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Have&amp;nbsp;2 dataset&amp;nbsp; looks like,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SUB_S	        LP_ACS_S
2718_AP1	2718_ACS_AP1
2718_AP2-A	2718_ACS_AP2
2718_AP2-C	2718_ACS_AP2
2718_AP3-A	2718_ACS_AP3
2718_AP3-B	2718_ACS_AP3
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired output is, given below. It's just a left join but if you look at the observations 2 and 4, we do have matching value in 'Have2'. In my desired output, I need the value and the logic is comparing '2718' and 'AP2' from SUB_S variable from 'Have1' with 'Have2' to get the corresponding LP_ACS_S value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;SUB_S	        ID	LP_ACS_S
2718_AP1	78.76	2718_ACS_AP1
2718_AP2-A	23.76	2718_ACS_AP2
2718_AP2-B	23.76	2718_ACS_AP2
2718_AP3-A	97.09	2718_ACS_AP3
2718_AP3-C	97.09	2718_ACS_AP3
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 17:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679561#M205206</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-26T17:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Join on substring from a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679566#M205207</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have1;
input SUB_S	 :$15.      ID;
cards;
2718_AP1	78.76
2718_AP2-A	23.76
2718_AP2-B	23.76
2718_AP3-A	97.09
2718_AP3-C	97.09
;

data have2;
input (SUB_S	        LP_ACS_S) (:$15.);
cards;
2718_AP1	2718_ACS_AP1
2718_AP2-A	2718_ACS_AP2
2718_AP2-C	2718_ACS_AP2
2718_AP3-A	2718_ACS_AP3
2718_AP3-B	2718_ACS_AP3
;

proc sql;
create table want as
select distinct a.*,LP_ACS_S
from have1 a left join have2 b
on substr(a.SUB_S,1,8)=substr(b.SUB_S,1,8);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Aug 2020 17:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679566#M205207</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-26T17:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Join on substring from a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679569#M205208</link>
      <description>Thanks. What if the values from 'Sub_S' in Have2 dataset has values like below and no change in Have1 dataset.&lt;BR /&gt;&lt;BR /&gt;2718_A_AP2&lt;BR /&gt;2718_C_AP2&lt;BR /&gt;2718_B_AP3&lt;BR /&gt;Now what function will you use in 'on' condition?</description>
      <pubDate>Wed, 26 Aug 2020 18:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679569#M205208</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-26T18:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Join on substring from a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679571#M205210</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp; -&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on substr(a.SUB_S,1,8)=catx('_',scan(b.SUB_S,1,'_'),scan(b.SUB_S,3,'_'));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Aug 2020 18:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-on-substring-from-a-variable/m-p/679571#M205210</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-26T18:18:24Z</dc:date>
    </item>
  </channel>
</rss>

