<?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: Length of  variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766652#M30665</link>
    <description>&lt;P&gt;So you have seen what results from the code, but why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When creating a new variable, SAS has to decide what length to use.&amp;nbsp; Why doesn't it use a length of 1, which is the third parameter to SUBSTR?&amp;nbsp; The answer is that the third parameter does not have to be hard-coded.&amp;nbsp; It could be an expression based on numeric variables on the data set (and could therefore vary from one observation to the next).&amp;nbsp; So SAS doesn't even examine the third parameter to decide what length to use.&amp;nbsp; To be safe, SAS decides to assign the length of the first parameter.&amp;nbsp; After all, it might need that length if SUBSTR happens to select the entire string.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Sep 2021 17:09:00 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-09-08T17:09:00Z</dc:date>
    <item>
      <title>Length of  variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766632#M30654</link>
      <description>&lt;P&gt;Hello Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am preparing for BASE SAS Specialist. A very common question in Dumps is to find the length of First Variable. I have coded in this SAS studio (Please Find the Code Below) and the length of the variable First is 200 but I am not able to find the reason for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please Let me know why length of the variable first (in below code) would be 200?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Author= 'Agatha Christie';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;First=substr(scan(author,1, ' '),1,1);&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;</description>
      <pubDate>Wed, 08 Sep 2021 16:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766632#M30654</guid>
      <dc:creator>SAS47</dc:creator>
      <dc:date>2021-09-08T16:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Length of  variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766635#M30656</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/396961"&gt;@SAS47&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am preparing for BASE SAS Specialist. A very common question in Dumps is to find the length of First Variable. I have coded in this SAS studio (Please Find the Code Below) and the length of the variable First is 200 but I am not able to find the reason for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please Let me know why length of the variable first (in below code) would be 200?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work.test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Author= 'Agatha Christie';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;First=substr(scan(author,1, ' '),1,1);&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Suggestion: Run that code and examine the result. Proc Contents is your friend when dealing with specific examples. Run the data step then contents and there's the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears that perhaps your SAS studio is not following the latest documentation (or the results from SAS 9.4) as I get 15 not 200.&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;&lt;A name="IDX2" target="_blank"&gt;&lt;/A&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Contents: Variables" cellspacing="0" cellpadding="3"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c m header" colspan="4" scope="colgroup"&gt;Alphabetic List of Variables and Attributes&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="c m header" scope="col"&gt;#&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;Variable&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;Type&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;Len&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;Author&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l m rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;First&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation for most, if not all, of the character manipulation functions will have a bit on what the default lengths are, and how they are assigned.&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n0n08xougp40i5n1xw7njpcy0a2b.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n0n08xougp40i5n1xw7njpcy0a2b.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;for example.&lt;/P&gt;
&lt;P&gt;Which says the variable would have the length of the first parameter.&lt;/P&gt;
&lt;P&gt;So you look at SCAN to see how it sets length as the first parameter to SUBSTR is the result of SCAN function.&lt;/P&gt;
&lt;P&gt;Which will use the length of it's first parameter, or that of Author.&lt;/P&gt;
&lt;P&gt;From &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;"In a DATA step, if the SCAN function returns a value to a variable that has not yet been given a length, that variable is given the length of the first argument."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a note about older versions of SAS set lengths of 200 for SCAN result, so be careful with older references. So perhaps your SAS Studio is connecting to something not running a recent release of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't know what "Dumps" is so can't comment on anything there.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 17:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766635#M30656</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-08T17:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Length of  variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766652#M30665</link>
      <description>&lt;P&gt;So you have seen what results from the code, but why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When creating a new variable, SAS has to decide what length to use.&amp;nbsp; Why doesn't it use a length of 1, which is the third parameter to SUBSTR?&amp;nbsp; The answer is that the third parameter does not have to be hard-coded.&amp;nbsp; It could be an expression based on numeric variables on the data set (and could therefore vary from one observation to the next).&amp;nbsp; So SAS doesn't even examine the third parameter to decide what length to use.&amp;nbsp; To be safe, SAS decides to assign the length of the first parameter.&amp;nbsp; After all, it might need that length if SUBSTR happens to select the entire string.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 17:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Length-of-variables/m-p/766652#M30665</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-09-08T17:09:00Z</dc:date>
    </item>
  </channel>
</rss>

