<?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 does SUBSTR= work with leading blanks in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574802#M162477</link>
    <description>&lt;P&gt;Not trying to replace X - just trying to visualize a sparse vector in plain text, so I want to build a long blank string and then populate segments of it using &lt;FONT face="courier new,courier"&gt;substr=.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Turns out I got an easier to read result by using a non-destructive function CATX(OF ....) to build my string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that background helps a litt.e&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2019 21:15:40 GMT</pubDate>
    <dc:creator>mftuchman</dc:creator>
    <dc:date>2019-07-18T21:15:40Z</dc:date>
    <item>
      <title>How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574714#M162449</link>
      <description>&lt;P&gt;What would you expect the output of this code to be?&amp;nbsp; What about the value of x in the 'v2' put statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length x $200;
x='?';
substr(x,70,1)='!';
put 'v1' x= $char200.;
x=' ';
substr(x,60,8)='la chose';
put 'v2' x= $char200.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the second one, I expected 59 blanks followed by the text.&amp;nbsp; This expectation was apparently in error.&amp;nbsp; How could I have predicted the observed behavior (X='la chose' with no leading blanks)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please don't ask me what I'm trying to do.&amp;nbsp; I already solved that; now I'm just curious as to how SUBSTR= works with blanks.&amp;nbsp; Th&lt;A title="substr(LEFT OF =) function" href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0uev77ebdwy90n1rsd7hwjd2qc3.htm" target="_blank" rel="noopener"&gt;e &lt;STRONG&gt;SUBSTR (left side of &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/STRONG&gt;&lt;/A&gt; page of the SAS documentation did not specify this behavior.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 18:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574714#M162449</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2019-07-18T18:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574717#M162451</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13767"&gt;@mftuchman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What would you expect the output of this code to be?&amp;nbsp; What about the value of x in the 'v2' put statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length x $200;
x='?';
substr(x,70,1)='!';
put 'v1' x= $char200.;
x=' ';
substr(x,60,8)='la chose';
put 'v2' x= $char200.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the second one, I expected 59 blanks followed by the text.&amp;nbsp; This expectation was apparently in error.&amp;nbsp; How could I have predicted the observed behavior (X='la chose' with no leading blanks)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please don't ask me what I'm trying to do.&amp;nbsp; I already solved that; now I'm just curious as to how SUBSTR= works with blanks.&amp;nbsp; Th&lt;A title="substr(LEFT OF =) function" href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0uev77ebdwy90n1rsd7hwjd2qc3.htm" target="_blank" rel="noopener"&gt;e &lt;STRONG&gt;SUBSTR (left side of &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/STRONG&gt;&lt;/A&gt; page of the SAS documentation did not specify this behavior.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;X= in the PUT statement specifies NAMED-PUT leading/trailing blanks are trimmed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   length x $200;
   x='?';
   substr(x,70,1)='!';
   put 'v1' x $char200.;
   x=' ';
   substr(x,60,8)='la chose';
   put 'v2' x $char200.;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 18:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574717#M162451</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-07-18T18:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574731#M162455</link>
      <description>&lt;P&gt;[to be deleted]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 21:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574731#M162455</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2019-07-18T21:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574755#M162460</link>
      <description>&lt;P&gt;Consider&lt;/P&gt;
&lt;PRE&gt;data junk;
length x $200;
x='?';
substr(x,70,1)='!';
put 'v1' x= $char200.;
x=' ';
substr(x,60,8)='la chose';
l = length(x);

run;
&lt;/PRE&gt;
&lt;P&gt;If you open the data set junk with any of the SAS viewers you will see a bunch of leading spaces. The value of L will count the leading spaces plus the actual text ending at the 'e' in 'chose'.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:41:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574755#M162460</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-18T19:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574767#M162466</link>
      <description>&lt;P&gt;Given that you seem to know what you are doing I am not sure I follow what the question is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS stores all character variables as fixed lengths strings that are padded with spaces.&amp;nbsp; So if you start with a missing/null/empty variable of length 200 it has 200 spaces in it.&amp;nbsp; If you then change 70th position into an X it now has 69 spaces one X and then 130 spaces.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 20:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574767#M162466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-18T20:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574769#M162468</link>
      <description>SUBSTR= does not replace X.  Instead, it replaces some of the characters in X (in this case, characters 60 through 67), leaving any other characters in X unchanged.</description>
      <pubDate>Thu, 18 Jul 2019 20:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574769#M162468</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-18T20:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574796#M162472</link>
      <description>&lt;P&gt;The question was originally "why do my leading spaces disappear?".&amp;nbsp; &amp;nbsp;Is it possible that SUBSTR= does not do what I think it does?&amp;nbsp; But it does; it was the named PUT that threw me off.&amp;nbsp; When I surrounded it with delimiters, the spaces were visible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I have to remember that single quote works for SAS, but not for English grammar &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 21:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574796#M162472</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2019-07-18T21:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How does SUBSTR= work with leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574802#M162477</link>
      <description>&lt;P&gt;Not trying to replace X - just trying to visualize a sparse vector in plain text, so I want to build a long blank string and then populate segments of it using &lt;FONT face="courier new,courier"&gt;substr=.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Turns out I got an easier to read result by using a non-destructive function CATX(OF ....) to build my string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that background helps a litt.e&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 21:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-does-SUBSTR-work-with-leading-blanks/m-p/574802#M162477</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2019-07-18T21:15:40Z</dc:date>
    </item>
  </channel>
</rss>

