<?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: Search and replace within a string of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788297#M252012</link>
    <description>&lt;P&gt;You do not want the TRANSLATE function in this sort of assignment. Translate changes character by character in the parameter lists. ALL 'M' become 'm' with your example. Note that the first parameter in Translate is the "to value list" and the second parameter is the "from value list". You wouldn't be the first person to confuse which order you want the parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;584      avisit = translate(avisit, 'Chmi', 'CHMI');&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You likely want the TRANWRD function which changes a group of characters for an entire different group, and the "from value" is the first parameter and the "to value" is the second parameter.&lt;/P&gt;
&lt;PRE&gt;avisit = tranwrd(avisit,'Chmi','CHMI');&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your "word" is possibly part of another word where you wouldn't want to change it you may need considerably more logic.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jan 2022 15:46:51 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-01-04T15:46:51Z</dc:date>
    <item>
      <title>Search and replace within a string of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788289#M252008</link>
      <description>&lt;P&gt;I want AVISIT to be proper case while maintaining all caps for my abbreviations.&lt;/P&gt;
&lt;P&gt;My attempt is yielding inconsistent outcomes...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 length visit $22.;
 input visit $20.;
 cards;
 INITIAL SCREENING
 MOCK CHMI DAY 1
 MOCK CHMI DAY 21
 CHMI1 DAY 1
 CHMI1 DAY 2
 CHMI2 DAY 1
 CHMI3 DAY 1
 CHMI3 DAY 8
 CHMI3 DAY 12
 ;
run;

data want;
 length visit $22.;
 input visit $20.;
 cards;
 Initial Screening
 Mock CHMI Day 1
 MOCK CHMI Day 21
 CHMI 1 Day 1
 CHMI 1 Day 2
 CHMI 2 Day 1
 CHMI 3 Day 1
 CHMI 3 Day 8
 CHMI 3 Day 12
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My attempt:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set have;
 avisit_ = propcase(visit);
 avisit = translate(avisit_, 'Chmi', 'CHMI ');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Outcome:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_0-1641307230379.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67105i6F612455B7DC2E44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_0-1641307230379.png" alt="mariko5797_0-1641307230379.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I initially attempted this code with more variables within a dataset and ended up with an empty column and this in the log file (the 'Note' repeated). VISIT format and informat are both characters, I don't quite understand why it is converting to numeric. The 'Note: Invalid numeric data...' is also not consistently written with each run, but I still get the conversion notes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;581  data test0;
582   set _work00_;
583      avisit = propcase(visit);
584      avisit = translate(avisit, 'Chmi', 'CHMI');
585      avisitn = visitnum;
586      *if avisit = 'Max Severity Post Baseline' then avisitn = 999;
587      ***;
588      atptn = scan(avisit, -1);
589      if find(avisit, 'Unscheduled') &amp;gt; 0 then atptn = scan(avisitn, 2);
590      if find(avisit, 'Screening') &amp;gt; 0 then atptn = 0.1;
591      if find(vstpt, 'POST MOCK') &amp;gt; 0 then atptn = 1.1;
592      if find(avisit, '28 Days After') &amp;gt; 0 then atptn = 28;
593      atpt = 'Day '||strip(atptn);
594
595      keep usubjid visit visitnum avisit avisitn vstpt atptn atpt;
596  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      583:14   584:14
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      584:24   588:18   589:13   589:58   590:13   590:51   591:50   592:13   592:55
NOTE: Invalid numeric data, 'Initial Screening' , at line 583 column 14.
NOTE: Invalid numeric data, 'Mock Chmi Day 1' , at line 583 column 14.

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does anyone have any ideas? Thank you in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 14:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788289#M252008</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2022-01-04T14:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Search and replace within a string of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788296#M252011</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set have;
 avisit_ = propcase(visit);
 avisit = tranwrd(avisit_, 'Chmi', 'CHMI ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jan 2022 15:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788296#M252011</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-04T15:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Search and replace within a string of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788297#M252012</link>
      <description>&lt;P&gt;You do not want the TRANSLATE function in this sort of assignment. Translate changes character by character in the parameter lists. ALL 'M' become 'm' with your example. Note that the first parameter in Translate is the "to value list" and the second parameter is the "from value list". You wouldn't be the first person to confuse which order you want the parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;584      avisit = translate(avisit, 'Chmi', 'CHMI');&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You likely want the TRANWRD function which changes a group of characters for an entire different group, and the "from value" is the first parameter and the "to value" is the second parameter.&lt;/P&gt;
&lt;PRE&gt;avisit = tranwrd(avisit,'Chmi','CHMI');&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your "word" is possibly part of another word where you wouldn't want to change it you may need considerably more logic.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 15:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-replace-within-a-string-of-variables/m-p/788297#M252012</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-04T15:46:51Z</dc:date>
    </item>
  </channel>
</rss>

