<?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: Is there any way to keep blank spaces in the end of a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600246#M173450</link>
    <description>&lt;P&gt;There will be as many spaces at the end of the string as the variable length allows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the variable is $10 the string is always&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;A='aaaaa&amp;nbsp; &amp;nbsp; &amp;nbsp;';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;If it is $5 it is&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;A='aaaaa';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This true regardless of the code. Only the variable length decides on the value.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;length A $10; A='a';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;yields&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;A='a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;length A $1; A='aaaa';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;yields&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;A='a';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2019 04:08:50 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-10-30T04:08:50Z</dc:date>
    <item>
      <title>Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600221#M173431</link>
      <description>&lt;P&gt;Hello Folks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to keep blank spaces in the end of a string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if I use the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;string_ = 'aaaaa&amp;nbsp; &amp;nbsp; &amp;nbsp;';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This column in the table will not show the 5 blanks at the end...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to concatenate some character columns, but the last column I have to fill with blank spaces in the end of the string, and use this string in a MD5 function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 00:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600221#M173431</guid>
      <dc:creator>Guiluiz</dc:creator>
      <dc:date>2019-10-30T00:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600223#M173433</link>
      <description>&lt;P&gt;The trailing spaces are padded with blanks as vlength function indicates???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
string_ = 'aaaaa     ';
v=vlength(string_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 00:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600223#M173433</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-30T00:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600224#M173434</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Blanks at the end of a string are preserved by default.&amp;nbsp; In fact, if you assign a value to a character variable and the value is shorter then the length of the variable, SAS will pad the value with blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In below example, STRING1 and STRING2 have the same value (5 a's followed by 5 blanks).&amp;nbsp; STRING3 has a different value (5 a's with no trailing blanks).&amp;nbsp; As expected, MD5() returns the same value for STRING1 and STRING2, and different value for STRING3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data a;
2       length string2 $10 ;
3       string1 = 'aaaaa     '; * $10 ;
4       string2 = 'aaaaa';      * $10 ;
5       string3 = 'aaaaa';      * $5  ;
6       hash1=md5(string1);
7       hash2=md5(string2);
8       hash3=md5(string3);
9       put string1=/ hash1=$hex32.;
10      put string2=/ hash2=$hex32.;
11      put string3=/ hash3=$hex32.;
12   run;

string1=aaaaa
hash1=410A99712BE19FDCBA336C42D1E81684
string2=aaaaa
hash2=410A99712BE19FDCBA336C42D1E81684
string3=aaaaa
hash3=594F803B380A41396ED63DCA39503542
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Q.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 01:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600224#M173434</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-10-30T01:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600246#M173450</link>
      <description>&lt;P&gt;There will be as many spaces at the end of the string as the variable length allows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the variable is $10 the string is always&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;A='aaaaa&amp;nbsp; &amp;nbsp; &amp;nbsp;';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;If it is $5 it is&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;A='aaaaa';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This true regardless of the code. Only the variable length decides on the value.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;length A $10; A='a';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;yields&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;A='a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;length A $1; A='aaaa';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;yields&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;A='a';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 04:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600246#M173450</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-30T04:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600280#M173460</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139676"&gt;@Guiluiz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Folks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to keep blank spaces in the end of a string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if I use the code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data example;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;string_ = 'aaaaa&amp;nbsp; &amp;nbsp; &amp;nbsp;';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This column in the table will not show the 5 blanks at the end...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to concatenate some character columns, but the last column I have to fill with blank spaces in the end of the string, and use this string in a MD5 function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's in the nature of blanks that they are invisible &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But they are there, see this proof:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
string_ = 'aaaaa     ';
hex_string = put(string_,$hex20.);
put hex_string=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;24         data example;
25         string_ = 'aaaaa     ';
26         hex_string = put(string_,$hex20.);
27         put hex_string=;
28         run;

hex_string=61616161612020202020
&lt;/PRE&gt;
&lt;P&gt;If you want to make sure that SAS writes the blanks to an external file (and does not cut a line short), use the $CHAR10. format for your string.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 07:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600280#M173460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-30T07:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600287#M173462</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139676"&gt;@Guiluiz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is about md5() then I'd be using the syntax used to populate variable &lt;EM&gt;digest2&lt;/EM&gt; below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The syntax for &lt;EM&gt;digest1&lt;/EM&gt;&amp;nbsp;should also work as long as the sum of the lengths of your source variables doesn't exceed a certain threshold.&lt;/P&gt;
&lt;P&gt;The MD5() function appears to have a limitation of how long a source string (the message) can be. I'm using in below example 3 SAS variables all with a length of 32KB. It appears that the md5() function doesn't use the whole concatenated string and though returns the same digest value for different combination of source variables.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  attrib  
    var1 var2 var3 length=$32767
    ;
  infile datalines dsd truncover;
  input (var1 var2 var3) (:$char32767.);
  digest1=put(md5(var1||var2||var3),hex32.);
  digest2=put(md5(trim(var1)||'|'||trim(var2)||'|'||trim(var3)),hex32.);
  datalines;
A,B,C
A,  B,C
A,,C
AB, C, 
ABC,,
 AB,C,
;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33476iEB110E070E41811A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW:&lt;/P&gt;
&lt;P&gt;If you're creating this digest value for some scd type 2 change tracking process then I suggest that you only concatenate variables up to the last non-blank value (=building something a bit more dynamic).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason for this: It allows you to later on add additional columns to a table but only for new columns which then also get a value a new change record will get inserted (IF in your logic you add new variables always at the end for concatenation).&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 23:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600287#M173462</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-04T23:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to keep blank spaces in the end of a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600290#M173464</link>
      <description>&lt;P&gt;As others have already written, SAS keeps the blanks in the end of a character variable, but they are not always displayed. But that does not mean that they are not there:&lt;/P&gt;
&lt;PRE&gt;13   data _null_;
14      y=md5('abc');
15      z=md5('abc ');
16      put y=$hex32.;
17      put z=$hex32.;
18   run;

y=900150983CD24FB0D6963F7D28E17F72
z=28A53E303DA9F5742476FD6B62434540
&lt;/PRE&gt;
&lt;P&gt;As you can see, the two values are different, because of the trailing blank in the second expression.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 08:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-way-to-keep-blank-spaces-in-the-end-of-a-string/m-p/600290#M173464</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-30T08:58:52Z</dc:date>
    </item>
  </channel>
</rss>

