<?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: Extract First 5 Characters of String Variable with Varying Lengths in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386304#M277214</link>
    <description>&lt;P&gt;If zip_char has leading blanks this might be the cause. Use the strip() function to get rid of blanks before applying substr().&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2017 15:38:24 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-08-08T15:38:24Z</dc:date>
    <item>
      <title>Extract First 5 Characters of String Variable with Varying Lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386300#M277211</link>
      <description>&lt;P&gt;I have a zip code variable in a dataset that includes both 5- and 9-digit zip codes. I want all of them to be 5-digits but am having trouble extracting the first 5 digits of the variable. It is an extensive list, but some examples are 15009, 15208, 191451652, 193760024.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to use substr,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data cases; set cases;&lt;/P&gt;&lt;P&gt;zip=substr(zip_char,1,5);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it seems to truncate the zip codes that are already 5 characters long to "1". Any thoughts on how to avoid this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386300#M277211</guid>
      <dc:creator>sstac</dc:creator>
      <dc:date>2017-08-08T15:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract First 5 Characters of String Variable with Varying Lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386302#M277212</link>
      <description>Perhaps your zip_char is right aligned. &lt;BR /&gt;Try to do left() prior to substr().</description>
      <pubDate>Tue, 08 Aug 2017 15:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386302#M277212</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-08-08T15:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract First 5 Characters of String Variable with Varying Lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386303#M277213</link>
      <description>&lt;P&gt;This would happen if ZIP_CHAR is not left-hand justified.&amp;nbsp; Luckily, it's easy to left-hand justify:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length zip $ 5;&lt;/P&gt;
&lt;P&gt;zip = left(zip_char);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SUBSTR isn't really needed, once you have assigned a length to the new variable.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386303#M277213</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-08T15:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract First 5 Characters of String Variable with Varying Lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386304#M277214</link>
      <description>&lt;P&gt;If zip_char has leading blanks this might be the cause. Use the strip() function to get rid of blanks before applying substr().&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-First-5-Characters-of-String-Variable-with-Varying/m-p/386304#M277214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-08T15:38:24Z</dc:date>
    </item>
  </channel>
</rss>

