<?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: SQL substr vs. ANSI substring: put-LeftAlign works differently in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692081#M210750</link>
    <description>&lt;P&gt;What troubles me here especially: the presence or non-presence of&amp;nbsp;&lt;EM&gt;one&lt;/EM&gt; function in the code has an influence on the workings of&amp;nbsp;&lt;EM&gt;another&lt;/EM&gt; function. This points to side-effects and a breach of compartmentalization. The old coder in me shivers with horror.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Oct 2020 09:02:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-10-16T09:02:13Z</dc:date>
    <item>
      <title>SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686682#M208420</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am currently optimizing and shortening some huge SQL code and came across a problem which I have no explanation for.&lt;/P&gt;&lt;P&gt;In some SQLs I use "put (..., 10.-L)" to create a new variable, I shortened it from "left (put (..., 10.))" before. All works fine, result is left-aligned. I copied the "put"-assignment to some other SQL code, and it does not work there, the resulting text is right-aligned.&lt;/P&gt;&lt;P&gt;I broke it down to a problem with creating substrings: using SAS's "substr" anywhere in the SQL statement the result is left-aligned, using the ANSI SQL "substring" it is suddenly right-aligned... to bad when used as a key to reference other tables. It is easy to code around this, but I would like to understand what is actually happening here.&lt;/P&gt;&lt;P&gt;Example code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;
  txt = 'DuMmY-TeXt';
  do nval=-5 to 5; output; end;
run;

data ds_tab; %*-- L-align in DataStep.  ;
  set dummy;
  tval_ds = put (nval, 10.-L);
run;

proc sql; %*--  L-align in SQL w/substr function SAS.  ;
  create table sql_tab_substr as
    select *,
           put (nval, 10.-L) as tval_sql_substr,
           substr (txt, 1, 1) as txt_sql_substr
    from ds_tab;
quit;

proc sql; %*--  L-align in SQL w/substrING function ANSI SQL.  ;
  create table sql_tab_substring as
    select *,
           put (nval, 10.-L) as tval_sql_substring,
           substring(txt from 1 for 1) as txt_sql_substring
    from sql_tab_substr;
quit;

data _null_;
  set sql_tab_substring;
  if _n_ = 1 then
    put 'From DS     SAS-sub     ANSI SQL';
  put tval_ds $10. '  ' tval_sql_substr $10. '  ' tval_sql_substring $10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Looking at the table or the log output I see that the put-L did not work when using "substring":&lt;/P&gt;&lt;PRE&gt;From DS     SAS-sub     ANSI SQL
-5          -5                  -5
-4          -4                  -4
-3          -3                  -3
-2          -2                  -2
-1          -1                  -1
0           0                    0
1           1                    1
2           2                    2
3           3                    3
4           4                    4
5           5                    5&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SQL_substr_vs_substring.png" style="width: 878px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49783i3E1AD1A535439D01/image-size/large?v=v2&amp;amp;px=999" role="button" title="SQL_substr_vs_substring.png" alt="SQL_substr_vs_substring.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Can anyone explain why a put-LEFT does not work anymore when using ANSI SQL "substring" in an SQL-statement? I have no clueless...&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Matthias&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 12:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686682#M208420</guid>
      <dc:creator>MatthiasB</dc:creator>
      <dc:date>2020-09-25T12:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686686#M208421</link>
      <description>&lt;P&gt;Bring this to the attention of SAS Technical Support. I think you have stumbled across a bug.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 13:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686686#M208421</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-25T13:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686718#M208434</link>
      <description>&lt;P&gt;Why are you using SUBSTRING() in PROC SQL instead of PROC FEDSQL?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 14:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686718#M208434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-25T14:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686857#M208468</link>
      <description>I am looking into existing SQL code written by testers and developers who are new to SAS development and not necessarily know some of the features. There is a mix of ANSI and SAS functions used here in PROC SQL, and when I step by step changed code blocks I made the format use -L to shorten left(put(...)) in all occurences. That broke the join on a key and I was nosy enough to investigate why one SQL did work and the other didn‘t. so mid of cleanup.</description>
      <pubDate>Fri, 25 Sep 2020 23:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/686857#M208468</guid>
      <dc:creator>MatthiasB</dc:creator>
      <dc:date>2020-09-25T23:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692053#M210733</link>
      <description>&lt;P&gt;This sure looks like a big fat bug.&lt;/P&gt;
&lt;P&gt;This &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n03g2uan994purn1lrpwnjg9cnx3.htm&amp;amp;locale=en" target="_self"&gt;function&lt;/A&gt; is supposed to work for proc sql and proc fedsql, and the wonky behaviour is the same with proc fedsql.&lt;/P&gt;
&lt;P&gt;Please keep us updated on what SAS TS says.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 06:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692053#M210733</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-16T06:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692070#M210745</link>
      <description>&lt;P&gt;Tech Support Germany has passed this on to Cary (mail conversation from Sep 28th), they reckon it will be 9.4 M7. Since I have a workaround, I had them close my ticket: didn't need to track this, especially since I have no control when which version is updated on servers here (z/OS and Linux, both on different TS-Levels). So, please watch out for M7 and "what's new" says.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 08:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692070#M210745</guid>
      <dc:creator>MatthiasB</dc:creator>
      <dc:date>2020-10-16T08:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: SQL substr vs. ANSI substring: put-LeftAlign works differently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692081#M210750</link>
      <description>&lt;P&gt;What troubles me here especially: the presence or non-presence of&amp;nbsp;&lt;EM&gt;one&lt;/EM&gt; function in the code has an influence on the workings of&amp;nbsp;&lt;EM&gt;another&lt;/EM&gt; function. This points to side-effects and a breach of compartmentalization. The old coder in me shivers with horror.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 09:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-substr-vs-ANSI-substring-put-LeftAlign-works-differently/m-p/692081#M210750</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-16T09:02:13Z</dc:date>
    </item>
  </channel>
</rss>

