<?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: BASE SAS Varying lengths of VARs when using CATX Character Manipulation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396006#M95572</link>
    <description>Do you think I am confusing CATX and CAT?</description>
    <pubDate>Thu, 14 Sep 2017 16:34:14 GMT</pubDate>
    <dc:creator>kmj636</dc:creator>
    <dc:date>2017-09-14T16:34:14Z</dc:date>
    <item>
      <title>BASE SAS Varying lengths of VARs when using CATX Character Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396003#M95570</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am studying for the Base Certification Exam and I have some questions over how SAS assigns length to VARs after using a character function such as CATX. So here are the things I think I know with CATX:&lt;/P&gt;&lt;P&gt;&amp;nbsp;a)&amp;nbsp;&amp;nbsp; the default byte length is &lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;b)&amp;nbsp;&amp;nbsp; the length statement can define the byte lenght to anything (when used at the top of the data step)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;c)&amp;nbsp;&amp;nbsp; the newly created VAR from CATX will assume the byte length of all the concatenated values such as byte &lt;STRONG&gt;5&lt;/STRONG&gt;!! byte2!! byte7 = NewCharacterVAR of 14bytes&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question then is, when are any of the character manipulation functions returning a value of &lt;STRONG&gt;200&lt;/STRONG&gt; when separating and concatenating? You are always creating a new character value when using these, correct? So are they not always going to be the sum of the VARs that make them up? I am really confused over the rules of character manipulation and anyone who could shed some light on this or point me in the direction of additional reading material would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all your help and time -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 16:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396003#M95570</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2017-09-14T16:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: BASE SAS Varying lengths of VARs when using CATX Character Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396006#M95572</link>
      <description>Do you think I am confusing CATX and CAT?</description>
      <pubDate>Thu, 14 Sep 2017 16:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396006#M95572</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2017-09-14T16:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: BASE SAS Varying lengths of VARs when using CATX Character Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396007#M95573</link>
      <description>&lt;P&gt;The best way to know is to test! &amp;nbsp;Write some code and see what SAS does with it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key thing is that you should always define your variables instead of forcing SAS to guess what you want.&lt;/P&gt;
&lt;P&gt;If it knows nothing about the variable other than that it is character then it will default to $8. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input str $ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if it can see that you are creating the variable from other variables then if can try to figure out how big it should be.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length x $10;
y=x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It can even figure some that involve operators or functions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length a b c $10;
x =a||b;
y=substr(c,1,5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But in general when it cannot figure out length of the function result will be for every possible input then it will use $200.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length a b c $50;
x = catx(',',a,b,c);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also watch out for using these in PROC SQL as some of them have shorter limits on what they can return when used in PROC SQL (at least they used to).&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 16:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396007#M95573</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-14T16:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: BASE SAS Varying lengths of VARs when using CATX Character Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396025#M95574</link>
      <description>&lt;P&gt;Thank you! Testing now&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 17:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396025#M95574</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2017-09-14T17:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: BASE SAS Varying lengths of VARs when using CATX Character Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396031#M95575</link>
      <description>&lt;P&gt;This was very helpful. Viewing the contents of these various scenarios was really helpful to understanding this. Thank you for your help and time.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 17:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396031#M95575</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2017-09-14T17:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: BASE SAS Varying lengths of VARs when using CATX Character Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396078#M95584</link>
      <description>&lt;P&gt;Reading the documentation can actually help. For instance from the online help for CATX:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 class="xis-title"&gt;Length of Returned Variable&lt;/H3&gt;
&lt;DIV class="xis-topicContent" id="p1vczom0a394qon19d2vk2wow4j0"&gt;
&lt;DIV class="xis-paragraph" id="n1mtvghhu0jyasn1bgg2ru765cvk"&gt;In a DATA step, if the CATX function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes. If the concatenation operator (||) returns a value to a variable that has not previously been assigned a length, then that variable is given a length that is the sum of the lengths of the values that are being concatenated.&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;So this paragraph shows why you may get different lengths with&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;y = catx(',', var1, var2);&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;and&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;y = var1||','||var2;&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;when y has not had a length assigned.&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 14 Sep 2017 20:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BASE-SAS-Varying-lengths-of-VARs-when-using-CATX-Character/m-p/396078#M95584</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-14T20:00:25Z</dc:date>
    </item>
  </channel>
</rss>

