<?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 truncation warning should NOT appear in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190505#M35930</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Remember that SUBSTR can be called with a variable as the third term, in which case there is no way of knowing at compile time whether the field will be truncated at run time - it's going to be data dependent.&amp;nbsp; I think we can infer that the compiler has been written to handle that as the general case, and hasn't had a special override added to say 'but if the user has specified a literal in position 3, check the table definition because we might not need the warning message after all.'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Jul 2014 21:59:36 GMT</pubDate>
    <dc:creator>dkb</dc:creator>
    <dc:date>2014-07-23T21:59:36Z</dc:date>
    <item>
      <title>SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190498#M35923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because the query includes the MD5 and one of the CAT* functions ( which default to $200 ), the INSERT below generates the warning below, even though the SUBSTR is supplying the length required.&amp;nbsp; SAS Tech Support suggested I use the option NOWARN but it's hardly tenable to turn off ALL warnings for something that SQL should ignore on its own.&amp;nbsp; Note that the DATA step does not throw a similar complaint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many installations will not allow production processes to throw warnings - let's see if we can get this fixed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;&lt;STRONG&gt;WARNING: Character expression will be truncated when assigned to character column hash_key.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create table asql as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select a.*&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; , md5('blah') as hash_key length=16&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; , catx('|',name,sex) as cats_var length=32&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; from sashelp.class ( obs = 0 ) a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; insert into asql &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select a.*&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; , &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;substr(&lt;/STRONG&gt;&lt;/SPAN&gt;md5(name || put(height,z3.) || put(weight,z6.2) || sex)&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;,1,16)&lt;/STRONG&gt;&lt;/SPAN&gt; as hash_key &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;length=16&lt;/STRONG&gt;&lt;/SPAN&gt; format=$hex32.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; , &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;substr(&lt;/STRONG&gt;&lt;/SPAN&gt;catx('|', name || put(height,z3.) || put(weight,z6.2) || sex)&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;,1,32)&lt;/STRONG&gt;&lt;/SPAN&gt; as cats_var &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;length=32 &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; from sashelp.class a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 21:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190498#M35923</guid>
      <dc:creator>droog</dc:creator>
      <dc:date>2014-07-22T21:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190499#M35924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Running just this part of the code:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sql; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;insert into asql &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a.* &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;, substr(md5(name || put(height,z3.) || put(weight,z6.2) || sex),1,16) as hash_key length=16 format=$hex32. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;, substr(catx('|', name || put(height,z3.) || put(weight,z6.2) || sex),1,32) as cats_var length=32 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from sashelp.class a &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument 3 to function SUBSTR. Missing values may be generated. &lt;/P&gt;&lt;P&gt;and not your warning with the second insert. The above may be masked because your second insert is in contention with the result of the invalid. Since cats_var has no | delimiter in the result I suggest you try using CATX the way it is intended&lt;/P&gt;&lt;P&gt;catx('|', name, put(height,z3.) , put(weight,z6.2) , sex) as using the || operator you generate one string and since there isn't a second there is no | inserted anywhere if your goal was to have a string like&lt;/P&gt;&lt;P&gt;Jane|060|084.50|F&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 23:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190499#M35924</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-07-22T23:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190500#M35925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, my sloppiness with copy / paste from two separate code sections has caused confusion.&amp;nbsp; Yes, of course the CATX should have commas betwixt the arguments, not the double pipe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But please see the subject line, &lt;STRONG&gt;why is the truncation WARNING appearing where it ought not&lt;/STRONG&gt; ?&amp;nbsp; i.e. the SUBSTR clearly sets the length in DATA step, shouldn't it do the same thing in SQL ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 00:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190500#M35925</guid>
      <dc:creator>droog</dc:creator>
      <dc:date>2014-07-23T00:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190501#M35926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Defining a view and using that to drive the update gets rid of the warnings...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create view aview as &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select a.*&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; , substrn(md5(name || put(height,z3.) || put(weight,z6.2) || sex),1,16) length=16 as hash_key&amp;nbsp; format=$hex32.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; , substrn(catx('|', name, put(height,z3.), put(weight,z6.2), sex),1,32) length=32 as cats_var &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; from sashelp.class a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; insert into asql&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select a.*&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; from aview a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this circumvention is helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 01:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190501#M35926</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2014-07-23T01:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190502#M35927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To build on &lt;A __default_attr="841015" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt; 's suggestion, you can use a subquery, such as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;insert into aSQL&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select * from (select md5(d) length=20 from test);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 02:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190502#M35927</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-07-23T02:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190503#M35928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks dkb and PGStats, both suggestions work.&amp;nbsp; Interesting that SQL "loses sight" of the apparent truncation if a sub-query or view is employed.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 11:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190503#M35928</guid>
      <dc:creator>droog</dc:creator>
      <dc:date>2014-07-23T11:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190504#M35929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think there is a certain logic to it. When you create a new table and set the length of a field with LENGTH=, it is your choice, it can be safely assumed that you know about the length of that field.No warning needed there.&amp;nbsp; When, on the other hand, you insert records into another table, the field lengths are defined elsewhere and you might not be aware of their true value. Thus the warning.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 14:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190504#M35929</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-07-23T14:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: SQL truncation warning should NOT appear</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190505#M35930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Remember that SUBSTR can be called with a variable as the third term, in which case there is no way of knowing at compile time whether the field will be truncated at run time - it's going to be data dependent.&amp;nbsp; I think we can infer that the compiler has been written to handle that as the general case, and hasn't had a special override added to say 'but if the user has specified a literal in position 3, check the table definition because we might not need the warning message after all.'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 21:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-truncation-warning-should-NOT-appear/m-p/190505#M35930</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2014-07-23T21:59:36Z</dc:date>
    </item>
  </channel>
</rss>

