<?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: why I can't use variable as a argument of the tranwrd function? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746624#M234224</link>
    <description>&lt;P&gt;the result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_0-1623194558016.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60161i16EDDAAC19C81189/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_0-1623194558016.png" alt="tianerhu_0-1623194558016.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;the result should be the following:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_1-1623194658794.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60162i2E1814F051D3E5E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_1-1623194658794.png" alt="tianerhu_1-1623194658794.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;the program is following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname cert xlsx 'C:\practice everyday\input\input08.xlsx';
libname results 'c:\cert';
data results.output08 (drop=province);
set cert.state;
province = scan(Location,2,' ');

Location = tranwrd(Location,province,upcase(province));
run;
proc print data = results.output08;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 08 Jun 2021 23:25:23 GMT</pubDate>
    <dc:creator>tianerhu</dc:creator>
    <dc:date>2021-06-08T23:25:23Z</dc:date>
    <item>
      <title>why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746615#M234217</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname cert xlsx 'C:\practice everyday\input\input08.xlsx';
libname results 'c:\cert';
data results.output08 (drop=province);
set cert.state;
province = scan(location,2,' ');

Location = tranwrd(Location,scan(location,2,' '),upcase(province));
run;
proc print data = results.output08;
run;



/* This program is replace in the same variable  */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to place the province variable instead of the second argument of tranwrd function, but it doesn't work , why ?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746615#M234217</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-06-08T23:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746618#M234220</link>
      <description>&lt;P&gt;What about it is not working? Show us.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746618#M234220</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-08T23:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746624#M234224</link>
      <description>&lt;P&gt;the result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_0-1623194558016.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60161i16EDDAAC19C81189/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_0-1623194558016.png" alt="tianerhu_0-1623194558016.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;the result should be the following:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_1-1623194658794.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60162i2E1814F051D3E5E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_1-1623194658794.png" alt="tianerhu_1-1623194658794.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;the program is following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname cert xlsx 'C:\practice everyday\input\input08.xlsx';
libname results 'c:\cert';
data results.output08 (drop=province);
set cert.state;
province = scan(Location,2,' ');

Location = tranwrd(Location,province,upcase(province));
run;
proc print data = results.output08;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746624#M234224</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-06-08T23:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746625#M234225</link>
      <description>&lt;P&gt;Provide sample input data following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not provide us your Excel file, most of us will not download Microsoft Office files.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746625#M234225</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-08T23:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746626#M234226</link>
      <description>&lt;P&gt;libname cert 'c:\cert\input';&lt;/P&gt;
&lt;P&gt;Data cert.input09;&lt;/P&gt;
&lt;P&gt;Input custID $;&lt;/P&gt;
&lt;P&gt;Datalines;&lt;/P&gt;
&lt;P&gt;ID1573&lt;/P&gt;
&lt;P&gt;ID2369&lt;/P&gt;
&lt;P&gt;ID5361&lt;/P&gt;
&lt;P&gt;ID8902&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746626#M234226</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-06-08T23:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746628#M234228</link>
      <description>&lt;P&gt;Okay, I'm lost. The CUSTID given cannot produce the outputs you want.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746628#M234228</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-08T23:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746629#M234229</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268447"&gt;@tianerhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname cert xlsx 'C:\practice everyday\input\input08.xlsx';
libname results 'c:\cert';
data results.output08 (drop=province);
set cert.state;
province = scan(location,2,' ');

Location = tranwrd(Location,scan(location,2,' '),upcase(province));
run;
proc print data = results.output08;
run;



/* This program is replace in the same variable  */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to place the province variable instead of the second argument of tranwrd function, but it doesn't work , why ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try something along these lines:&lt;/P&gt;
&lt;PRE&gt;data junk;
   location = 'Something gobbledygook and other words';
   province = scan(location,2,' ');
   Location = tranwrd(Location,strip(scan(location,2,' ')),upcase(strip(province)));
run;&lt;/PRE&gt;
&lt;P&gt;What is happening is that the SCAN function is returning a value the length of your Location variable.&lt;/P&gt;
&lt;P&gt;So when used in the Tranwrd function there are trailing blanks in the results that make the result long enough that the "words" after the Province no longer fit in the result.&lt;/P&gt;
&lt;P&gt;If you use your original code creating a new variable instead of reusing Location it will work as well.&lt;/P&gt;
&lt;P&gt;From the documentation for Tranwrd with some elements highlighted:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="p0fmlwl9u29sazn14k9kh60nkha1" class="xis-subTopic"&gt;
&lt;DIV id="n0e89pq2ulc6p1n1q2bq6b3jtb6g" class="xis-topicContent"&gt;
&lt;DIV id="n0pf2uqx3srktwn0zr1yafcmfunv" class="xis-paragraph"&gt;The TRANWRD function copies the value in &lt;SPAN class="xis-userSuppliedValue"&gt;source&lt;/SPAN&gt; to the result string while searching for all non-overlapping substrings in &lt;SPAN class="xis-userSuppliedValue"&gt;source&lt;/SPAN&gt; that are equal to the value in &lt;SPAN class="xis-userSuppliedValue"&gt;target&lt;/SPAN&gt;. Each of these substrings is omitted from the result and the value of &lt;SPAN class="xis-userSuppliedValue"&gt;replacement&lt;/SPAN&gt; is copied in its place. The TRANWRD function &lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt;does not remove trailing blanks in the &lt;SPAN class="xis-userSuppliedValue"&gt;target&lt;/SPAN&gt; string or the &lt;SPAN class="xis-userSuppliedValue"&gt;replacement&lt;/SPAN&gt; string&lt;/FONT&gt;&lt;/STRONG&gt;.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So &lt;STRONG&gt;you&lt;/STRONG&gt; need to remove the trailing blanks returned by SCAN (in two places) and pay attention to the rules involved for creating new variables with some of these string functions.&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>Tue, 08 Jun 2021 23:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746629#M234229</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-08T23:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746634#M234233</link>
      <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 01:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746634#M234233</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-06-09T01:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: why I can't use variable as a argument of the tranwrd function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746635#M234234</link>
      <description>&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 01:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-I-can-t-use-variable-as-a-argument-of-the-tranwrd-function/m-p/746635#M234234</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-06-09T01:14:45Z</dc:date>
    </item>
  </channel>
</rss>

