<?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: Use a reference table to find a string in dataset and replace it in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711152#M219011</link>
    <description>&lt;P&gt;It would have been much nicer to have the delimiter character after the object string.&amp;nbsp; That's a messy problem.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I would refer you to PRXMATCH.&amp;nbsp; Regular expressions save you the need to write lots of SAS code.&amp;nbsp; Your regular expression might be "\:/d/d:(object)\", replacing&amp;nbsp;(object) for each know&amp;nbsp;object string.&lt;/LI&gt;
&lt;LI&gt;If you don't you can use FIND.&amp;nbsp; More complicated find ":" then verify the next two characters a numbers and the third is ":" again.&amp;nbsp; then then string after matches one of your object strings.&amp;nbsp; Much more code in this case.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=vdmmlcdc&amp;amp;cdcVersion=8.1&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0bj9p4401w3n9n1gmv6tf**bleep**9m.htm&amp;amp;locale=en"&gt;SAS Help Center: PRXMATCH Function&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p00ab6ey29t2i8n1ihel88tqtga9.htm&amp;amp;locale=en"&gt;SAS Help Center: FIND Function&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2021 15:18:04 GMT</pubDate>
    <dc:creator>PhilC</dc:creator>
    <dc:date>2021-01-13T15:18:04Z</dc:date>
    <item>
      <title>Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711068#M218975</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below 3 tables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1 (Main Table)&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp;message_1 &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;message_2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;catcansiton:50:&lt;U&gt;31123&lt;/U&gt;nearby&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catcansiton:50:&lt;U&gt;MJKXY32&lt;/U&gt;nearby&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;dogcaneat:60:&lt;U&gt;54637&lt;/U&gt;fruit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dogcaneat:60:&lt;U&gt;DMF67XXM&lt;/U&gt;fruit&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;beesand:30:&lt;U&gt;BOTKXXM&amp;nbsp;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;beesand:30:&lt;U&gt;64590&lt;/U&gt;&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp;colorofsky:40:&lt;U&gt;DMF67XXM&lt;/U&gt;blue &amp;nbsp; &amp;nbsp; colorofsky:40:&lt;U&gt;54637&lt;/U&gt;blue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2 (Reference table)&lt;/P&gt;&lt;P&gt;Object_1 &amp;nbsp; &amp;nbsp; &amp;nbsp;Object_2&lt;/P&gt;&lt;P&gt;&lt;U&gt;31123&lt;/U&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;U&gt;MJKXY32&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;54637&lt;/U&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;DMF67XXM&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;64590&lt;/U&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;U&gt;BOTKXXM&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output Table (Output Desired)&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp;message_1 &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;message_2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;catcansiton:50:&lt;U&gt;31123&lt;/U&gt;nearby&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catcansiton:50:&lt;U&gt;31123&lt;/U&gt;nearby&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;dogcaneat:60:&lt;U&gt;54637&lt;/U&gt;fruit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dogcaneat:60:&lt;U&gt;54637&lt;/U&gt;fruit&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;beesand:30:&lt;U&gt;64590&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;beesand:30:&lt;U&gt;64590&lt;/U&gt;&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp;colorofsky:40:&lt;U&gt;54637&lt;/U&gt;blue &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; colorofsky:40:&lt;U&gt;54637&lt;/U&gt;blue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a main table which has message_1 and message_2 fields which are partially same, except for the codes in the middle which start with either of the four&amp;nbsp;:30:, :40:, :50: and :60: strings before them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a separate reference table which I want to use to look up the the objects and replace them by other object in the main table either to message1 or message_2 and get the desired output. Can you please guide me with how to use a reference table to find the data in the main table ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 13:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711068#M218975</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-13T13:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711075#M218978</link>
      <description>&lt;P&gt;So you know what preceeds the strings of interest? Do you also know what comes after?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 13:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711075#M218978</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-13T13:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711109#M218990</link>
      <description>&lt;P&gt;Good questions.&amp;nbsp; Also are the object strings always capital and are the "words" after the object strings always lowercase, containing no numbers?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711109#M218990</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-13T14:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711113#M218992</link>
      <description>&lt;P&gt;After the desired string could be any characters, there are all small or caps and alphanumeric. but the :30:, :40:, :50: and :60: are fixed preset codes to my desired reference codes in the main table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711113#M218992</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-13T14:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711152#M219011</link>
      <description>&lt;P&gt;It would have been much nicer to have the delimiter character after the object string.&amp;nbsp; That's a messy problem.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I would refer you to PRXMATCH.&amp;nbsp; Regular expressions save you the need to write lots of SAS code.&amp;nbsp; Your regular expression might be "\:/d/d:(object)\", replacing&amp;nbsp;(object) for each know&amp;nbsp;object string.&lt;/LI&gt;
&lt;LI&gt;If you don't you can use FIND.&amp;nbsp; More complicated find ":" then verify the next two characters a numbers and the third is ":" again.&amp;nbsp; then then string after matches one of your object strings.&amp;nbsp; Much more code in this case.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=vdmmlcdc&amp;amp;cdcVersion=8.1&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0bj9p4401w3n9n1gmv6tf**bleep**9m.htm&amp;amp;locale=en"&gt;SAS Help Center: PRXMATCH Function&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p00ab6ey29t2i8n1ihel88tqtga9.htm&amp;amp;locale=en"&gt;SAS Help Center: FIND Function&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 15:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711152#M219011</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-13T15:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711165#M219017</link>
      <description>&lt;P&gt;1) I suppose that each message has 3 substrings delimited by colon ':', in such case you can&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; subtract it by:&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;third_str = scan(message,3,':');&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2) Does data have messages that do not contain the ':20:', ':30:' ,':40:', ':60:' codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if positive you need skip those messages.&lt;/P&gt;
&lt;P&gt;3) I do not understand the rules for replacing the substrings ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Next code joines the two tables up to point for replacing substrings:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data main;  /* MAIN table */
   length message_1 message_2 $40; /* adapt length to data */
   infile cards truncover;
   input ID message_1 $ message_2 $;
cards;
1    catcansiton:50:31123nearby    catcansiton:50:MJKXY32nearby
2    dogcaneat:60:54637fruit       dogcaneat:60:DMF67XXMfruit
3    beesand:30:BOTKXXM            beesand:30:64590
4    colorofsky:40:DMF67XXMblue    colorofsky:40:54637blue
; run;

data refer;  /* Reference table */
   length object_1 object_2 $20; /* adapt length to expected data */
   infile cards truncover;
   input object_1 $ object_2 $;
cards;
31123   MJKXY32
54637   DMF67XXM
64590   BOTKXXM 
; run;

data temp1;  /* Extract substring to check vs refernece */
 set main;
   length submsg1 submsg2 $20;
   submsg1 = scan(message_1,3,':');
   submsg2 = scan(message_2,3,':');
run;

proc sql;
   create table temp2 as
   select a.* , b.*
   from temp1 as a 
   left join refer as b 
   on index(a.message_1, submsg1) &amp;gt; 0 or
      index(a.message_1, submsg2) &amp;gt; 0 or
	  index(a.message_2, submsg1) &amp;gt; 0 or
	  index(a.message_2, submsg2) &amp;gt; 0 ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; next step need to complete:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set temp2;
     if index(a.submsg1, object_1) &amp;gt; 0 then do;
         /* replace substring and output */
     end;
     if index(a.submsg1, object_2) &amp;gt; 0 then do;
         /* replace substring and output */
     end;
     if index(a.submsg2, object_1) &amp;gt; 0 then do;
         /* replace substring and output */
     end;
     if index(a.submsg2, object_2) &amp;gt; 0 then do;
         /* replace substring and output */
     end;
      
run;
&lt;/CODE&gt;&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;</description>
      <pubDate>Wed, 13 Jan 2021 15:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711165#M219017</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-13T15:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711197#M219036</link>
      <description>&lt;P&gt;Thank you, the answer to the questions.&lt;/P&gt;&lt;P&gt;1. Each message does not have fixed number of substrings that can be repeated by : , hence the only way to determine the position of the string that needs to be replaced is between those fixed 4 code i.e. :30:, :40:, :50:, :60:&lt;/P&gt;&lt;P&gt;2. All the messages have either of these codes which come before and after the string that needs to be replaced.&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g. &amp;nbsp;message_1 &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;message 2 &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;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abcs:30:&lt;STRONG&gt;34629&lt;/STRONG&gt;:60:hdjckhd &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abcs:30:&lt;STRONG&gt;BTKXX347&lt;/STRONG&gt;:60:hdjckhd &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;so the string in bold is the reference table string, so I have to convert the string in Message_2 using reference table to make it look like message_1 for comparison. &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 16:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711197#M219036</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-13T16:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711200#M219037</link>
      <description>&lt;P&gt;This problem became much easier.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 16:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711200#M219037</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-13T16:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711211#M219042</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361602"&gt;@SAS_New_User1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, the answer to the questions.&lt;/P&gt;
&lt;P&gt;1. Each message does not have fixed number of substrings that can be repeated by : , hence the only way to determine the position of the string that needs to be replaced is between those fixed 4 code i.e. :30:, :40:, :50:, :60:&lt;/P&gt;
&lt;P&gt;2. All the messages have either of these codes which come before and after the string that needs to be replaced.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. &amp;nbsp;message_1 &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;message 2 &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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abcs:30:&lt;STRONG&gt;34629&lt;/STRONG&gt;:60:hdjckhd &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abcs:30:&lt;STRONG&gt;BTKXX347&lt;/STRONG&gt;:60:hdjckhd &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the string in bold is the reference table string, so I have to convert the string in Message_2 using reference table to make it look like message_1 for comparison. &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1) In your 1st post the message contains only one code not two.&lt;/P&gt;
&lt;P&gt;2) You can replace codes to one character to be used as a delimiter - let's say '09'x (a tab)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;by using tranw() function for each of the 4 codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;That enables use &lt;STRONG&gt;scan(message,2,'09'x)&lt;/STRONG&gt; to extract the mid substring.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711211#M219042</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-13T17:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use a reference table to find a string in dataset and replace it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711229#M219056</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;has a good solution.&amp;nbsp; I was following and I wrote this code.&amp;nbsp; If it adds to the discussion.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;  /* MAIN table */
   length ID 8 message_1 message_2 $40; /* adapt length to data */
   infile cards truncover;
   input ID message_1 $ message_2 $;
cards;
1    catcansiton:50:31123:60:nearby    catcansiton:50:MJKXY32:40:nearby
2    dogcaneat:60:54637:30:fruit       dogcaneat:60:DMF67XXM:40:fruit
3    beesand:30:BOTKXXM:60:            beesand:30:64590:30:
4    colorofsky:40:DMF67XXM:30:blue    colorofsky:40:54637:30:blue
; run;

proc format ;
  value $object_correct
    "MJKXY32"  = "31123"
    "DMF67XXM" = "54637"
    "BOTKXXM"  = "64590"
    other = " "
    ;
run;

data want (Keep= ID message_1	message_2)
;  /* Extract substring to check vs refernece */
/*  if 0 then set refer;*/
  set main;
   array m[2,5] $ m11 m12 object_1 m14 m15 
                  m21 m22 object_2 m24 m25 ;
   
   do i=1 to 5; drop i;
     m[1,i]=scan(message_1,i,':');
     m[2,i]=scan(message_2,i,':');
   end;

   if put(object_1,$object_correct.)= object_2
     then message_1=catx(":",m11, m12, object_2, m14, m15);
   if put(object_2,$object_correct.)= object_1
     then message_2=catx(":",m21, m22, object_1, m24, m25);

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have a whole dataset of "objects"-"object" pairs then you can follow the below example to create a format from a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1e19y6lrektafn1kj6nbvhus59w.htm&amp;amp;locale=en"&gt;SAS Help Center: Creating a Format from a CNTLIN= Data Set&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-reference-table-to-find-a-string-in-dataset-and-replace-it/m-p/711229#M219056</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-13T17:44:38Z</dc:date>
    </item>
  </channel>
</rss>

