<?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: Vlookup Search and compare strings and update values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Vlookup-Search-and-compare-strings-and-update-values/m-p/585516#M166979</link>
    <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  A(index=(OLD_TRAIT_ID));
 input NEW_TRAIT_ID $10. OLD_TRAIT_ID $;
cards;
16070843T	74160T
16070844T	16981T
16070847T	79556T
run;
data B;
  SEGMENT_RULE='(74160T OR 16981T) AND (79556T)';
run;
data WANT;
  set B;
  length NEW_RULE $200;
  NEW_RULE=SEGMENT_RULE;
  do I=1 to countw(SEGMENT_RULE,' ()');
    OLD_TRAIT_ID=scan(SEGMENT_RULE,I,' ()');
    if length(OLD_TRAIT_ID)&amp;lt;6 then continue;
    set A key=OLD_TRAIT_ID;   
    if _IORC_ then do;
      _ERROR_=0;
      continue;
    end;      
    NEW_RULE=tranwrd(NEW_RULE,trim(OLD_TRAIT_ID),catx(' OR ',OLD_TRAIT_ID,NEW_TRAIT_ID));    
  end;
run;
proc print noobs; 
  var NEW_RULE;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;NEW_RULE&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;(74160T OR 16070843T OR 16981T OR 16070844T ) AND (79556T OR 16070847T )&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 01 Sep 2019 23:27:28 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-09-01T23:27:28Z</dc:date>
    <item>
      <title>Vlookup Search and compare strings and update values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vlookup-Search-and-compare-strings-and-update-values/m-p/585206#M166843</link>
      <description>&lt;P&gt;Hi, Fellow community members !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to vlookup of two data set and update strings for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to compare the column&amp;nbsp; "Old trait id" to the dataset B for matches and update the matches in Dataset B by appending "New trait id" with string "OR".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset A&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NEW TRAIT ID&lt;/TD&gt;&lt;TD&gt;OLD TRAIT ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16070843T&lt;/TD&gt;&lt;TD&gt;74160T&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16070844T&lt;/TD&gt;&lt;TD&gt;16981T&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16070847T&lt;/TD&gt;&lt;TD&gt;79556T&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Dataset B&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;segmentRule&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;(74160T OR 16981T) AND (79556T)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Output&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;(74160T OR 16070843T OR 16981T OR 16070844T) AND (79556T OR 16070847T)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 30 Aug 2019 13:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vlookup-Search-and-compare-strings-and-update-values/m-p/585206#M166843</guid>
      <dc:creator>anuragchoubey</dc:creator>
      <dc:date>2019-08-30T13:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Search and compare strings and update values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vlookup-Search-and-compare-strings-and-update-values/m-p/585516#M166979</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  A(index=(OLD_TRAIT_ID));
 input NEW_TRAIT_ID $10. OLD_TRAIT_ID $;
cards;
16070843T	74160T
16070844T	16981T
16070847T	79556T
run;
data B;
  SEGMENT_RULE='(74160T OR 16981T) AND (79556T)';
run;
data WANT;
  set B;
  length NEW_RULE $200;
  NEW_RULE=SEGMENT_RULE;
  do I=1 to countw(SEGMENT_RULE,' ()');
    OLD_TRAIT_ID=scan(SEGMENT_RULE,I,' ()');
    if length(OLD_TRAIT_ID)&amp;lt;6 then continue;
    set A key=OLD_TRAIT_ID;   
    if _IORC_ then do;
      _ERROR_=0;
      continue;
    end;      
    NEW_RULE=tranwrd(NEW_RULE,trim(OLD_TRAIT_ID),catx(' OR ',OLD_TRAIT_ID,NEW_TRAIT_ID));    
  end;
run;
proc print noobs; 
  var NEW_RULE;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;NEW_RULE&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;(74160T OR 16070843T OR 16981T OR 16070844T ) AND (79556T OR 16070847T )&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Sep 2019 23:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vlookup-Search-and-compare-strings-and-update-values/m-p/585516#M166979</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-09-01T23:27:28Z</dc:date>
    </item>
  </channel>
</rss>

