<?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: Cutting a String in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93661#M26554</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One more obscure possibility:&amp;nbsp; perhaps SHRCD is character, but contains leading blanks.&amp;nbsp; After the LENGTH statement, simply add:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HEADER = left(SHRCD);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Dec 2012 14:15:38 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2012-12-07T14:15:38Z</dc:date>
    <item>
      <title>Cutting a String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93659#M26552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been trying to cut out a portion of the observations, but unsuccessful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I have 2 digits, eg. 11, 12, 22, 31,... ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to cut and isolate the first digit under a new variable named "Header"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So header will have 1, 1, 2, 3,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code I used:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA CRSP;&lt;/P&gt;&lt;P&gt;SET CRSP;&lt;/P&gt;&lt;P&gt;Length HEADER $1.; &lt;/P&gt;&lt;P&gt;HEADER=SUBSTR(SHRCD,1);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, Header will have no observations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please Heap!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 11:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93659#M26552</guid>
      <dc:creator>Benn</dc:creator>
      <dc:date>2012-12-07T11:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting a String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93660#M26553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HEADER = put(SHRCD,best.-l) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that works then a bunch of the assumptions that we had to make (since you provided no log) could be true.&lt;/P&gt;&lt;P&gt;Assumptions such as&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;SHRCD is numeric and not character&lt;BR /&gt;So the log would have told us by mentioning 'Numeric values have been converted to character ...'&lt;/LI&gt;&lt;LI&gt;"Header will have no observations" should be "Header will be blank"&lt;BR /&gt;Happens when SHRCD is numeric and the value is per default right justified in an eight byte field&lt;BR /&gt;of which you extract (by means of SUBSTR) position one i.e. a blank&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now why would the above work without invoking function SUBSTR?&lt;/P&gt;&lt;P&gt;That's because the length of HEADER has already been declared as one byte. (Note BTW the statement has to be "length header $1", i.e. no dot after $1 . We are declaring the length here and not assigning a format.)&lt;/P&gt;&lt;P&gt;Transferring a longer character variable's value to a shorter variable results in the value being truncated at the shorter variable's length.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oh, and&amp;nbsp; "best.-L" means: "write out the numeric value justified left in a format optimal for the field length".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this heaps&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 11:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93660#M26553</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2012-12-07T11:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting a String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93661#M26554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One more obscure possibility:&amp;nbsp; perhaps SHRCD is character, but contains leading blanks.&amp;nbsp; After the LENGTH statement, simply add:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HEADER = left(SHRCD);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 14:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93661#M26554</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-12-07T14:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting a String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93662#M26555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If shrcd is numeric and not character&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;header=floor(shrcd/10);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 15:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cutting-a-String/m-p/93662#M26555</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-12-07T15:56:09Z</dc:date>
    </item>
  </channel>
</rss>

