<?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: A problem with controlling the length with PROC SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150938#M39748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is really weird .report it to sas support . see how they say it .&lt;/P&gt;&lt;P&gt;Here is a workaround way . build a table construct before full the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length a 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; a=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length a 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; a=2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; create table one_and_two like data1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;insert into&amp;nbsp; one_and_two &lt;/P&gt;&lt;P&gt;&amp;nbsp; select a&amp;nbsp; from data1&lt;/P&gt;&lt;P&gt;&amp;nbsp; union all corr&lt;/P&gt;&lt;P&gt;&amp;nbsp; select a&amp;nbsp; from data2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Aug 2014 12:07:22 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-08-06T12:07:22Z</dc:date>
    <item>
      <title>A problem with controlling the length with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150936#M39746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wonder why it gives me problems to control the length of a variable in a dataset constructed with proc sql.&lt;/P&gt;&lt;P&gt;It seems that when the "union all" is used then the length of a numerical variable can not be specified. Here is my example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length a 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; a=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length a 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; a=2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table one_and_two as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select a length=3 from data1&lt;/P&gt;&lt;P&gt;&amp;nbsp; union all&lt;/P&gt;&lt;P&gt;&amp;nbsp; select a length=3 from data2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the "one_and_two" dataset the length of the variable "a" is now 8! I would have expected it should be 3.&lt;/P&gt;&lt;P&gt;If I do the same as above with a character variable, then there is no problem in controling the length. Also, If there is no union then&amp;nbsp; the length&amp;nbsp; can also be controlled. Any explanation for that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 11:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150936#M39746</guid>
      <dc:creator>JacobSimonsen</dc:creator>
      <dc:date>2014-08-06T11:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: A problem with controlling the length with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150937#M39747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting. Another point on my (steadliy growing longer) list of "SQL is evil".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: Found a working method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table one_and_two as select a length=3 from&lt;/P&gt;&lt;P&gt;&amp;nbsp; (select a from data1&lt;/P&gt;&lt;P&gt;&amp;nbsp; union all&lt;/P&gt;&lt;P&gt;&amp;nbsp; select a from data2);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But&lt;/P&gt;&lt;P&gt;data one_and_two;&lt;/P&gt;&lt;P&gt;set data1 data2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;is much simpler and works also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 11:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150937#M39747</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-08-06T11:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: A problem with controlling the length with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150938#M39748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is really weird .report it to sas support . see how they say it .&lt;/P&gt;&lt;P&gt;Here is a workaround way . build a table construct before full the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length a 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; a=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length a 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; a=2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; create table one_and_two like data1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;insert into&amp;nbsp; one_and_two &lt;/P&gt;&lt;P&gt;&amp;nbsp; select a&amp;nbsp; from data1&lt;/P&gt;&lt;P&gt;&amp;nbsp; union all corr&lt;/P&gt;&lt;P&gt;&amp;nbsp; select a&amp;nbsp; from data2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 12:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150938#M39748</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-06T12:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: A problem with controlling the length with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150939#M39749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;interesting yes checked and behavior as described. SQL is evil agree on that. &lt;BR /&gt;Even more as most DBA's do not know the difference between numeric and character still living in the Hollerith card age.&lt;/P&gt;&lt;P&gt;Explanation on that.&lt;/P&gt;&lt;P&gt;- Doing measurements you have real numbers that are in generic approach of floating type (8 bytes).&lt;/P&gt;&lt;P&gt;- Classifications ordinal/nominal are of text types (length 1-*)&lt;/P&gt;&lt;P&gt;&amp;nbsp; Telling female =1 male=2 would say the mean of sex = 1.5. A classic example of nonsense statistics. In this case 1 and 2 are still characters that have limited valid range of values.&lt;/P&gt;&lt;P&gt;&amp;nbsp; That are constraints.&amp;nbsp;&amp;nbsp; There are 10 types of people in this world, those who understand binary and those who don't&lt;A href="http://www.urbandictionary.com/define.php?term=there%20are%2010%20types%20of%20people%20in%20this%20world%2C%20those%20who%20understand%20binary%20and%20those%20who%20dont&amp;amp;defid=4067341"&gt;http://www.urbandictionary.com/define.php?term=there%20are%2010%20types%20of%20people%20in%20this%20world%2C%20those%20who%20understand%20binary%20and%20those%20who%20dont&amp;amp;defid=4067341&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the length question: is not very sensible trying to limit numeric lengths as of effects loss of precision.&lt;/P&gt;&lt;P&gt;It looks as the union is using the default length setting for all SAS numerics, some kind of protection for beginners or not implemented the shortening.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The datastep is faster on this and gives more control &lt;/P&gt;&lt;P&gt;Would you prefer a more strict datatype approach. There is new language "DS2" and another SQL implementation FedSql &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 12:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150939#M39749</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-06T12:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: A problem with controlling the length with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150940#M39750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I think what is happening is this:&lt;/P&gt;&lt;P&gt;step 1 - the engine sees a union all&lt;/P&gt;&lt;P&gt;2 - it creates a table in the background examining the variables in table 1&lt;/P&gt;&lt;P&gt;3 - the table is assigned as num - default length&lt;/P&gt;&lt;P&gt;4 - the data is inserted&lt;/P&gt;&lt;P&gt;5 - then the next set of data&lt;/P&gt;&lt;P&gt;(not complete)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;KurtBremser's solutions works by creating the table explicitly with the create table statement, and then the temporary table behind the scenes would then be inserted into that.&amp;nbsp; Same with yours KSharp.&amp;nbsp; Table creation first then insert the data.&amp;nbsp; You can fool it with inputs as well:&lt;/P&gt;&lt;P&gt;proc sql _method _tree;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table one_and_two as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select input(put(a,best.),3.) length=3 from data1&lt;/P&gt;&lt;P&gt;&amp;nbsp; union all&lt;/P&gt;&lt;P&gt;&amp;nbsp; select a from data2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So from an SQL point of view, think about what you want the final table to look like, order, lengths, variables etc.&amp;nbsp; then add the data into it. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 13:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150940#M39750</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-08-06T13:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: A problem with controlling the length with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150941#M39751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As shown above it is not difficult to find a work around, and the question is therefore not how a workaround should be done. It is simple, and the dataset approach is like the easiest way.&lt;/P&gt;&lt;P&gt;Rather, the question is why SQL do something different from what expected. I am happy that you experts also find it strange, so it is not just me who have overlooked something trivial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your answers:smileyblush:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 15:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/A-problem-with-controlling-the-length-with-PROC-SQL/m-p/150941#M39751</guid>
      <dc:creator>JacobSimonsen</dc:creator>
      <dc:date>2014-08-06T15:16:39Z</dc:date>
    </item>
  </channel>
</rss>

