<?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 Select Variables based on character length in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424538#M27350</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to add a leading '0' to variables within a field that are less that 5 characters in length. Does anyone know of a bit of code that can achieve this? Below is my attempt. I know&amp;nbsp;everything after 'THEN' works fine, its the selecting&amp;nbsp;variables with less than 5 characters that is hindering me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CASE&lt;BR /&gt;WHEN substr(t1.ded_code,max(1,length(t1.ded_code)-3)) THEN PUT(INPUT(t1.ded_code, best.), z2.)&lt;BR /&gt;ELSE t1.ded_code&lt;BR /&gt;END&lt;BR /&gt;AS ded_code_v2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Finbar&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2018 10:59:06 GMT</pubDate>
    <dc:creator>fgillen1</dc:creator>
    <dc:date>2018-01-03T10:59:06Z</dc:date>
    <item>
      <title>Select Variables based on character length</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424538#M27350</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to add a leading '0' to variables within a field that are less that 5 characters in length. Does anyone know of a bit of code that can achieve this? Below is my attempt. I know&amp;nbsp;everything after 'THEN' works fine, its the selecting&amp;nbsp;variables with less than 5 characters that is hindering me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CASE&lt;BR /&gt;WHEN substr(t1.ded_code,max(1,length(t1.ded_code)-3)) THEN PUT(INPUT(t1.ded_code, best.), z2.)&lt;BR /&gt;ELSE t1.ded_code&lt;BR /&gt;END&lt;BR /&gt;AS ded_code_v2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Finbar&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 10:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424538#M27350</guid>
      <dc:creator>fgillen1</dc:creator>
      <dc:date>2018-01-03T10:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select Variables based on character length</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424541#M27351</link>
      <description>&lt;P&gt;You can simplify it by using SAS functions:&lt;/P&gt;
&lt;PRE&gt;case when lengthn(T1.DED_CODE) &amp;lt; 5 then cats(repeat("0",5-lengthn(T1.DED_CODE)),T1.DED_CODE)
     else T1.DED_CODE end as DED_CODE_V2&lt;/PRE&gt;
&lt;P&gt;So if the trimmed lenght is less than five concatenate 0 for each space less than five.&amp;nbsp; Note, if DED_CODE is numeric, you could simplify this further by:&lt;/P&gt;
&lt;PRE&gt;put(input(T1.DED_CODE,best.),z5.) as DED_CODE_V2&lt;/PRE&gt;
&lt;P&gt;The Z format padds out numbers with preceeding zeroes.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 11:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424541#M27351</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-03T11:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Select Variables based on character length</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424546#M27352</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks! That works fine, I just changed&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;cats(repeat("0",5-lengthn(T1.DED_CODE))&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE&gt;cats(repeat("0",4-lengthn(T1.DED_CODE))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;the first one was throwing in two leading '0's&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Finbar&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 11:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Variables-based-on-character-length/m-p/424546#M27352</guid>
      <dc:creator>fgillen1</dc:creator>
      <dc:date>2018-01-03T11:14:06Z</dc:date>
    </item>
  </channel>
</rss>

