<?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 Length of new variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701552#M25772</link>
    <description>&lt;PRE&gt;data scoredata1;&lt;BR /&gt;set scoredata0;&lt;BR /&gt;length phone_update $10; /*without this the length will be 200*/&lt;BR /&gt;phone_update = TRANWRD(phone,'000','408');&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;when I use TRANWRD to replace '000' of 'phone' by '408', I find that a length definition is needed for the new variable of 'phone_update". Otherwise, the length of phone_update will be 200. Will all new variables defined by a function require to define its length?&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I note that this is different for a trim and CATX functions:&lt;/P&gt;&lt;PRE&gt;data scoredata2;&lt;BR /&gt;set scoredata1;&lt;BR /&gt;/*the concatenation operator and Trim function*/&lt;BR /&gt;student_name1 = trim(last_name) || ', ' || trim(first_name);&lt;BR /&gt;/*the CATX function enables you to concatenate character strings, &lt;BR /&gt;remove leading and trailing blanks, and insert separators*/&lt;BR /&gt;length student_name2 $25;&lt;BR /&gt;student_name2 = catx(', ',last_name,first_name);&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;the student_name1 by trim is defined by the input variables, last_name and first-name, while the length of student_name2 is 200 if removing the length function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a bit confused when a length definition is needed. will a length of 200 slow down the operation and take too much memory space? The length of variables can be easily checked through&lt;/P&gt;&lt;P&gt;proc contents data=xxx&lt;/P&gt;&lt;P&gt;run;&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;&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, 25 Nov 2020 15:18:13 GMT</pubDate>
    <dc:creator>anming</dc:creator>
    <dc:date>2020-11-25T15:18:13Z</dc:date>
    <item>
      <title>Length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701552#M25772</link>
      <description>&lt;PRE&gt;data scoredata1;&lt;BR /&gt;set scoredata0;&lt;BR /&gt;length phone_update $10; /*without this the length will be 200*/&lt;BR /&gt;phone_update = TRANWRD(phone,'000','408');&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;when I use TRANWRD to replace '000' of 'phone' by '408', I find that a length definition is needed for the new variable of 'phone_update". Otherwise, the length of phone_update will be 200. Will all new variables defined by a function require to define its length?&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I note that this is different for a trim and CATX functions:&lt;/P&gt;&lt;PRE&gt;data scoredata2;&lt;BR /&gt;set scoredata1;&lt;BR /&gt;/*the concatenation operator and Trim function*/&lt;BR /&gt;student_name1 = trim(last_name) || ', ' || trim(first_name);&lt;BR /&gt;/*the CATX function enables you to concatenate character strings, &lt;BR /&gt;remove leading and trailing blanks, and insert separators*/&lt;BR /&gt;length student_name2 $25;&lt;BR /&gt;student_name2 = catx(', ',last_name,first_name);&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;the student_name1 by trim is defined by the input variables, last_name and first-name, while the length of student_name2 is 200 if removing the length function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a bit confused when a length definition is needed. will a length of 200 slow down the operation and take too much memory space? The length of variables can be easily checked through&lt;/P&gt;&lt;P&gt;proc contents data=xxx&lt;/P&gt;&lt;P&gt;run;&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;&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, 25 Nov 2020 15:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701552#M25772</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-11-25T15:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701570#M25775</link>
      <description>With TRANWRD, the result can be longer than the source. Therefore the function causes the data step compiler to use the default length of 200, if no length is specified. See Maxim 47.</description>
      <pubDate>Wed, 25 Nov 2020 16:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701570#M25775</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-25T16:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701574#M25776</link>
      <description>&lt;P&gt;The documentation for each of the character functions usually indicates the default length of the resulting variable if a length is not assigned but 200 is common. Trim, Strip, Compress and Compbl functions do not change the length because the only operation they do is shift or remove characters inside the value. So if the start is 20 characters any shifting/removing will fit inside 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Too much memory", possibly depending on number of variables though disk space is more likely the issue.&lt;/P&gt;
&lt;P&gt;Moving extra bits around for read/ write operations may slow things down. If you only have a few variables and data sets of less than a 1000 records you may not notice the difference. When you get to 1000's of variables and millions of records then the performance is more likely to be noticeable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of the reason is that depending on the functions used the length of results is unpredictable. Tranwrd for example could replace 3 characters with 100. Instead of spending a lot of time "guessing" from your code possibly results SAS picks 200 (which used to be the maximum length of character variables). Another reason is that with simple assignment statements the first use of the variable would set the length. So if your first result was small then other results later might not fit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is another example of the Maxim Know thy Data.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Length-of-new-variables/m-p/701574#M25776</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-25T16:35:28Z</dc:date>
    </item>
  </channel>
</rss>

