<?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: How to retain trailing blanks in substr function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354323#M82870</link>
    <description>&lt;P&gt;Replace&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;four=length(two)&lt;/EM&gt; with&amp;nbsp;&lt;EM&gt;four=lengthc(two)&lt;/EM&gt; and you will see that the trailing blanks are kept in variable two.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
one= "abc ";
two=substr(one, 3);
three=lengthc(one);
four=lengthc(two);
five = cat('"', two, '"');
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Apr 2017 02:05:26 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-04-28T02:05:26Z</dc:date>
    <item>
      <title>How to retain trailing blanks in substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354322#M82869</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While using substring function, it ignores the trailing blanks , and i need to retain the trailing blanks of the string,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;one= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"abc "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;two=substr(one,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;three=lengthc(one);&lt;/P&gt;&lt;P&gt;four=length(two);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;this is the output&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;one two three&amp;nbsp; four&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;abc&amp;nbsp;c&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 01:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354322#M82869</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2017-04-28T01:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain trailing blanks in substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354323#M82870</link>
      <description>&lt;P&gt;Replace&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;four=length(two)&lt;/EM&gt; with&amp;nbsp;&lt;EM&gt;four=lengthc(two)&lt;/EM&gt; and you will see that the trailing blanks are kept in variable two.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
one= "abc ";
two=substr(one, 3);
three=lengthc(one);
four=lengthc(two);
five = cat('"', two, '"');
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 02:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354323#M82870</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-28T02:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain trailing blanks in substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354348#M82888</link>
      <description>&lt;P&gt;When you put a string into a SAS character variable that is shorter than the defined length of the variable, then it is &lt;U&gt;always&lt;/U&gt; padded with blanks (unless you use substr() on the left side).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
length x1 $5 x2 $10 x3 $20;
x1 = 'AAAAA';
x2 = 'XXXXXXXXXX';
x3 = put(x2,$hex20.);
output;
x2 = x1;
x3 = put(x2,$hex20.);
output;
run;

proc print data=test noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; x1      x2                     x3

AAAAA    XXXXXXXXXX    58585858585858585858
AAAAA    AAAAA         41414141412020202020
&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 06:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-trailing-blanks-in-substr-function/m-p/354348#M82888</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-28T06:41:38Z</dc:date>
    </item>
  </channel>
</rss>

