<?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 SAS Tip: Caution with the TRANWRD Function! in SAS Tips from the Community</title>
    <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Caution-with-the-TRANWRD-Function/m-p/441737#M203</link>
    <description>&lt;P&gt;Did you know that: the TRANWRD function, which can replace or remove all occurrences of a given word, has a hidden gotcha?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The gotcha is that, if you do not provide a length statement for a new variable that will receive the output from the TRANWRD function, it will default to a length of 200 characters. The inimitable Ron Cody pointed this out in his SUGI 31 paper&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="external text" href="http://www2.sas.com/proceedings/sugi31/247-31.pdf" rel="nofollow" target="_blank"&gt;An Introduction to SAS Character Functions&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Here is an example of the gotcha:&lt;/P&gt;
&lt;DIV class="mw-geshi mw-code mw-content-ltr" dir="ltr"&gt;
&lt;DIV class="sas source-sas"&gt;
&lt;PRE class="de1"&gt;&lt;SPAN class="kw6"&gt;data&lt;/SPAN&gt; &lt;SPAN class="kw1"&gt;_null_&lt;/SPAN&gt;;
    &lt;SPAN class="kw3"&gt;length&lt;/SPAN&gt; newstatement1 $34;
&amp;nbsp;
    statement = &lt;SPAN class="st0"&gt;"I enjoy going to SUGI conferences."&lt;/SPAN&gt;;
    newstatement1 = &lt;SPAN class="kw3"&gt;tranwrd&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;statement,&lt;SPAN class="st0"&gt;"SUGI"&lt;/SPAN&gt;, &lt;SPAN class="st0"&gt;"SGF"&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    newstatement2 = &lt;SPAN class="kw3"&gt;tranwrd&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;statement,&lt;SPAN class="st0"&gt;"SUGI"&lt;/SPAN&gt;, &lt;SPAN class="st0"&gt;"SGF"&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&amp;nbsp;
    length_newstatement1 = lengthc&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;newstatement1&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    length_newstatement2 = lengthc&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;newstatement2&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&amp;nbsp;
    &lt;SPAN class="kw3"&gt;put&lt;/SPAN&gt; length_newstatement1 =&amp;nbsp;;
    &lt;SPAN class="kw3"&gt;put&lt;/SPAN&gt; length_newstatement2 =&amp;nbsp;;
&lt;SPAN class="kw6"&gt;run&lt;/SPAN&gt;;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;If you submit the code, above, you will see that newstatement1 ends up with a length of 34, while newstatement2 ends up with a length of 200. That is because newstatement1 had a length statement specifying its size before it was used with the TRANWRD function; while newstatement2 was created fresh and new when used in the TRANWRD function and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SAS--not knowing what to make of this infant variable--decided to make it 200 characters in length; the TRANWRD default.&lt;/P&gt;
&lt;P&gt;So, what is the gotcha? The gotcha is that you could end up with larger variables than you intend to--needlessly inflating the size of a SAS data set--if you are not careful to declare the length of a new SAS character variable that will be created by using the TRANWRD function. You have been warned!&lt;/P&gt;
&lt;P&gt;Other functions, such as SUBSTR, will also generate long character variables.&lt;/P&gt;
&lt;P&gt;A secondary issue is that when the returned value exceeds 200 characters, truncation will occur if you have not properly set the length of the new variable.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Thanks to MMMMIIIIKKKKEEEE&amp;nbsp;for sharing this tip on sasCommunity.org.&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2019 20:12:51 GMT</pubDate>
    <dc:creator>SAS_Tipster</dc:creator>
    <dc:date>2019-05-09T20:12:51Z</dc:date>
    <item>
      <title>SAS Tip: Caution with the TRANWRD Function!</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Caution-with-the-TRANWRD-Function/m-p/441737#M203</link>
      <description>&lt;P&gt;Did you know that: the TRANWRD function, which can replace or remove all occurrences of a given word, has a hidden gotcha?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The gotcha is that, if you do not provide a length statement for a new variable that will receive the output from the TRANWRD function, it will default to a length of 200 characters. The inimitable Ron Cody pointed this out in his SUGI 31 paper&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="external text" href="http://www2.sas.com/proceedings/sugi31/247-31.pdf" rel="nofollow" target="_blank"&gt;An Introduction to SAS Character Functions&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Here is an example of the gotcha:&lt;/P&gt;
&lt;DIV class="mw-geshi mw-code mw-content-ltr" dir="ltr"&gt;
&lt;DIV class="sas source-sas"&gt;
&lt;PRE class="de1"&gt;&lt;SPAN class="kw6"&gt;data&lt;/SPAN&gt; &lt;SPAN class="kw1"&gt;_null_&lt;/SPAN&gt;;
    &lt;SPAN class="kw3"&gt;length&lt;/SPAN&gt; newstatement1 $34;
&amp;nbsp;
    statement = &lt;SPAN class="st0"&gt;"I enjoy going to SUGI conferences."&lt;/SPAN&gt;;
    newstatement1 = &lt;SPAN class="kw3"&gt;tranwrd&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;statement,&lt;SPAN class="st0"&gt;"SUGI"&lt;/SPAN&gt;, &lt;SPAN class="st0"&gt;"SGF"&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    newstatement2 = &lt;SPAN class="kw3"&gt;tranwrd&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;statement,&lt;SPAN class="st0"&gt;"SUGI"&lt;/SPAN&gt;, &lt;SPAN class="st0"&gt;"SGF"&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&amp;nbsp;
    length_newstatement1 = lengthc&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;newstatement1&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    length_newstatement2 = lengthc&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;newstatement2&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&amp;nbsp;
    &lt;SPAN class="kw3"&gt;put&lt;/SPAN&gt; length_newstatement1 =&amp;nbsp;;
    &lt;SPAN class="kw3"&gt;put&lt;/SPAN&gt; length_newstatement2 =&amp;nbsp;;
&lt;SPAN class="kw6"&gt;run&lt;/SPAN&gt;;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;If you submit the code, above, you will see that newstatement1 ends up with a length of 34, while newstatement2 ends up with a length of 200. That is because newstatement1 had a length statement specifying its size before it was used with the TRANWRD function; while newstatement2 was created fresh and new when used in the TRANWRD function and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SAS--not knowing what to make of this infant variable--decided to make it 200 characters in length; the TRANWRD default.&lt;/P&gt;
&lt;P&gt;So, what is the gotcha? The gotcha is that you could end up with larger variables than you intend to--needlessly inflating the size of a SAS data set--if you are not careful to declare the length of a new SAS character variable that will be created by using the TRANWRD function. You have been warned!&lt;/P&gt;
&lt;P&gt;Other functions, such as SUBSTR, will also generate long character variables.&lt;/P&gt;
&lt;P&gt;A secondary issue is that when the returned value exceeds 200 characters, truncation will occur if you have not properly set the length of the new variable.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Thanks to MMMMIIIIKKKKEEEE&amp;nbsp;for sharing this tip on sasCommunity.org.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 20:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Caution-with-the-TRANWRD-Function/m-p/441737#M203</guid>
      <dc:creator>SAS_Tipster</dc:creator>
      <dc:date>2019-05-09T20:12:51Z</dc:date>
    </item>
  </channel>
</rss>

