<?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: Change length of character variable to match another in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924739#M44629</link>
    <description>&lt;P&gt;Have you checked to see if there is any value past the 15th character?&lt;/P&gt;
&lt;P&gt;If so, you may need to make some decisions about what text value to keep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The technique is simple: add a length statement to that data step &lt;STRONG&gt;before&lt;/STRONG&gt; the Set statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data table2 (keep=state plan);
rename state_r = state ptypcd=plan;
length &amp;lt;variable&amp;gt; &amp;lt;new length i.e. $ 15&amp;gt;;
set table1;
run;&lt;/PRE&gt;
&lt;P&gt;However your rename means that the variable name would be the OLD one so it modifies the existing variable what the values are brought in.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2024 18:47:19 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-04-17T18:47:19Z</dc:date>
    <item>
      <title>Change length of character variable to match another</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924738#M44628</link>
      <description>&lt;P&gt;I want to format the variable plan.&amp;nbsp; Right now it's $24 CHAR but the table it joins to later after this step has plan as $15. CHAR:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data table2 (keep=state plan);&lt;BR /&gt;rename state_r = state ptypcd=plan;&lt;/P&gt;
&lt;P&gt;set table1;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 17:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924738#M44628</guid>
      <dc:creator>bhca60</dc:creator>
      <dc:date>2024-04-17T17:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Change length of character variable to match another</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924739#M44629</link>
      <description>&lt;P&gt;Have you checked to see if there is any value past the 15th character?&lt;/P&gt;
&lt;P&gt;If so, you may need to make some decisions about what text value to keep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The technique is simple: add a length statement to that data step &lt;STRONG&gt;before&lt;/STRONG&gt; the Set statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data table2 (keep=state plan);
rename state_r = state ptypcd=plan;
length &amp;lt;variable&amp;gt; &amp;lt;new length i.e. $ 15&amp;gt;;
set table1;
run;&lt;/PRE&gt;
&lt;P&gt;However your rename means that the variable name would be the OLD one so it modifies the existing variable what the values are brought in.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 18:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924739#M44629</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-17T18:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change length of character variable to match another</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924745#M44632</link>
      <description>&lt;P&gt;You are using the verb&amp;nbsp; "format" ambiguously.&amp;nbsp; In SAS a format is something that determines how to display a value as text.&amp;nbsp; You can attach different formats to a variable and have the values display differently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you want to change the LENGTH of a character variable.&amp;nbsp; In that case you should also take care that the variable does not have a format attached to it that will impact how it is displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to change it to be length 15 from length 24 then you need to worry about lose of data.&amp;nbsp; It might be safest to make a new variable and also check the current values before copying them to the new variable to make sure they will fit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table2 ;
  set table1;
  length plan $15  ;
  state=state_r ;
  plan=ptypcd ;
  if length(ptypcd) &amp;gt; 15 then put 'NOTE: Data will be truncated. ' _n_= ptypcd= plan=;
  keep state plan;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2024 19:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-length-of-character-variable-to-match-another/m-p/924745#M44632</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-17T19:10:42Z</dc:date>
    </item>
  </channel>
</rss>

