<?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: string match between two variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680795#M205832</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID var1 :$12. var2 :$12.;
datalines;
1 11,21,43,35 11
2 11,21,43,25 20,21,35,43
3 11 35
4 11,21,35 21,35
5 21 35,21,43
;
data want;
	set have;
	nvar1=countw(var1,',');
	nvar2=countw(var2,',');
	length match $ 30;
	match=' ';
	do i=1 to nvar1;
		do j=1 to nvar2;
			if scan(var1,i,',')=scan(var2,j,',') then match=catx(',',match,scan(var1,i,','));
		end;
	end;
	drop i j nvar:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Sep 2020 19:02:54 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-01T19:02:54Z</dc:date>
    <item>
      <title>string match between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680790#M205828</link>
      <description>&lt;P&gt;I have a dataset with 2000 observations. It contains ID, var1, var2.&lt;/P&gt;&lt;P&gt;Var1="11,21,43,35" or "11" or any combination of these numbers. sometimes just one number, sometimes two numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var2="20,21,35,43" or&amp;nbsp;&amp;nbsp;or any combination of these numbers. sometimes just one number, sometimes two numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to generate a new variable to find any overlap or matching numbers between these two variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, when var1="11,21,43,25" and var2="20,21,35,43"&amp;nbsp; then matching="21";&lt;/P&gt;&lt;P&gt;when var1="11" and var2="35" then matching=.;&lt;/P&gt;&lt;P&gt;when var1="11,21,35" and var2="21,35,43" then matching="21,35".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;BR /&gt;input ID var1 $ var2 $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 11,21,43,35 11&lt;BR /&gt;2 11,21,43,25 20,21,35,43&lt;BR /&gt;3 11 35&lt;BR /&gt;4 11,21,35 21,35&lt;BR /&gt;5 21 35,21,43&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 18:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680790#M205828</guid>
      <dc:creator>linda0910</dc:creator>
      <dc:date>2020-09-01T18:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: string match between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680795#M205832</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID var1 :$12. var2 :$12.;
datalines;
1 11,21,43,35 11
2 11,21,43,25 20,21,35,43
3 11 35
4 11,21,35 21,35
5 21 35,21,43
;
data want;
	set have;
	nvar1=countw(var1,',');
	nvar2=countw(var2,',');
	length match $ 30;
	match=' ';
	do i=1 to nvar1;
		do j=1 to nvar2;
			if scan(var1,i,',')=scan(var2,j,',') then match=catx(',',match,scan(var1,i,','));
		end;
	end;
	drop i j nvar:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Sep 2020 19:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680795#M205832</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-01T19:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: string match between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680801#M205838</link>
      <description>Thanks a lot. It works perfectly.</description>
      <pubDate>Tue, 01 Sep 2020 19:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/string-match-between-two-variables/m-p/680801#M205838</guid>
      <dc:creator>linda0910</dc:creator>
      <dc:date>2020-09-01T19:16:41Z</dc:date>
    </item>
  </channel>
</rss>

