<?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: Compare two variables and output the matching string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510699#M137447</link>
    <description>&lt;P&gt;Do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length VAR1 $50;
input VAR1 $ VAR2 $;
infile datalines dlm='|';
datalines;
1.LMK 2.ABC NM 3.ABC 4.XYZ|ABC, XYZ
1.ABC|ABC, XYZ
1.XYZ|ABC, XYZ
;

data want(drop=i string);
   set have;
   length want $100;
   do i=1 to countw(VAR2);
      string=strip(scan(VAR2, i, ','));
      if find(VAR1, string, 'it') &amp;gt; 0 then want=catx(',', want, string);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Nov 2018 08:31:35 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-11-06T08:31:35Z</dc:date>
    <item>
      <title>Compare two variables and output the matching string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510690#M137445</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two columns: 1. is my list of treatment drugs given to a patient (multiple, can have the study drug or cannot have the study drug) and 2 is my list of drug related to the study(separated by a coma, constant/fixed).&lt;/P&gt;&lt;P&gt;My requirement is i have to search for rows where my list of study drugs has been given to the patient. and display all those separated by coma.&lt;/P&gt;&lt;P&gt;I have my main dataset to which each row i have merged my list of drug(combined into coma separated).&lt;/P&gt;&lt;P&gt;VAR1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; VAR2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WANT&lt;/P&gt;&lt;P&gt;1.LMK 2.ABC NM 3.ABC 4.XYZ&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABC, XYZ&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABC, XYZ&lt;/P&gt;&lt;P&gt;1.ABC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABC, XYZ&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABC&lt;/P&gt;&lt;P&gt;1.XYZ&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABC, XYZ&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XYZ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 07:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510690#M137445</guid>
      <dc:creator>augustcrez</dc:creator>
      <dc:date>2018-11-06T07:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two variables and output the matching string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510699#M137447</link>
      <description>&lt;P&gt;Do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length VAR1 $50;
input VAR1 $ VAR2 $;
infile datalines dlm='|';
datalines;
1.LMK 2.ABC NM 3.ABC 4.XYZ|ABC, XYZ
1.ABC|ABC, XYZ
1.XYZ|ABC, XYZ
;

data want(drop=i string);
   set have;
   length want $100;
   do i=1 to countw(VAR2);
      string=strip(scan(VAR2, i, ','));
      if find(VAR1, string, 'it') &amp;gt; 0 then want=catx(',', want, string);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Nov 2018 08:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510699#M137447</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-06T08:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two variables and output the matching string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510711#M137449</link>
      <description>&lt;P&gt;Please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    
data want;
set have;
count=countw(var2,',');
array xvar(*) $ xvars1-xvars10;
do i = 1 to count;
if index(var1,strip(scan(var2,i,','))) then xvar(i)=scan(var2,i,',');
end;
newvar=catx(',',of xvars1-xvars10);&lt;BR /&gt;drop xvars:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Nov 2018 09:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/510711#M137449</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-11-06T09:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two variables and output the matching string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/512080#M137887</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both the solutions work fine for me in most of the rows but i also found a case which is as follows&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;length VAR1 $50 var2 $50;&lt;BR /&gt;input VAR1 $ VAR2 $;&lt;BR /&gt;infile datalines dlm='|';&lt;BR /&gt;datalines;&lt;BR /&gt;1.LMK 2.ABCNM 3.XYZ|ABCNM, XYZ, NM&lt;BR /&gt;1.ABC|ABCNM, XYZ, NM&lt;BR /&gt;1.XYZ|ABCNM, XYZ, NM&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here in my first now my resultant should be only "ABCNM, XYZ" but i get "ABCNM,XYZ,NM" which shouldnt be the case as im looking for exact matches&lt;/P&gt;&lt;P&gt;Also can i apply formats to these drugnames at the same time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 04:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/512080#M137887</guid>
      <dc:creator>augustcrez</dc:creator>
      <dc:date>2018-11-12T04:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two variables and output the matching string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/512122#M137894</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both the solutions work fine for me in most of the rows but i also found a case which is as follows&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;length VAR1 $50 var2 $50;&lt;BR /&gt;input VAR1 $ VAR2 $;&lt;BR /&gt;infile datalines dlm='|';&lt;BR /&gt;datalines;&lt;BR /&gt;1.LMK 2.ABCNM 3.XYZ|ABCNM, XYZ, NM&lt;BR /&gt;1.ABC|ABCNM, XYZ, NM&lt;BR /&gt;1.XYZ|ABCNM, XYZ, NM&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here in my first now my resultant should be only "ABCNM, XYZ" but i get "ABCNM,XYZ,NM" which shouldnt be the case as im looking for exact matches&lt;/P&gt;&lt;P&gt;Also can i apply formats to these drugnames at the same time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 09:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-variables-and-output-the-matching-string/m-p/512122#M137894</guid>
      <dc:creator>augustcrez</dc:creator>
      <dc:date>2018-11-12T09:16:42Z</dc:date>
    </item>
  </channel>
</rss>

