<?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: Insert missing values into DB2 in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235644#M6027</link>
    <description>&lt;P&gt;If that's the case, it's sounds like the situation I described.&lt;/P&gt;
&lt;P&gt;We solved that issue by setting&amp;nbsp;&lt;SPAN&gt;IGNORE_READ_ONLY_COLUMNS=YES, which in out case made the columns under automatic constraints&amp;nbsp;be invisible for the SAS client, and not regarded&amp;nbsp;during insert/append operations.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Nov 2015 11:53:24 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2015-11-20T11:53:24Z</dc:date>
    <item>
      <title>Insert missing values into DB2</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235622#M6022</link>
      <description>&lt;P&gt;In a DB2 database I have a table with the following attributes:&lt;/P&gt;&lt;PRE&gt;NAME     TYPE    NULLABLE DEFAULT
CHAR_COL CHAR    N
NUM_COL  INTEGER N        1&lt;/PRE&gt;&lt;P&gt;I.e. the two columns cannot be empty and the NUM_COL should be assigned the default value 1 if a missing value is inserted. If I want to insert data into this table from SAS I expect rows where CHAR_COL is missing to be rejected and rows where NUM_COL is missing should be accepted and assign the default value 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If using the INSERT statement I can insert an&amp;nbsp;empty string&amp;nbsp;into a character column even if this is against the DB2 constrains. I assume this is due to missing value for a character column is ‘ ‘ (a blank space) and not a NULL value in SAS. This method can however&amp;nbsp;assign the default value to column NUM_COL.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data to_be_rejected;
	char_col = '';
  	num_col = 123;
	output;
run;

libname db2db db2 datasrc=xxx user=xxx password=xxx schema='xxx';

proc sql noprint; 
	insert into db2db.db2table(char_col,num_col)
	select char_col,num_col from work.to_be_rejected;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If using the APPEND statement DB2 does not accept empty character values but does not assigned missing values the default value.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data to_be_accepted;
	char_col = 'aaa';
  	num_col = .;
	output;
run;

proc datasets nolist;
	append base=db2db.db2table data=work.to_be_accepted nowarn force;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I insert data into this table using a method that both reject missing character values and let DB2 assign the default value?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 07:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235622#M6022</guid>
      <dc:creator>Rikard</dc:creator>
      <dc:date>2015-11-20T07:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Insert missing values into DB2</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235631#M6024</link>
      <description>&lt;P&gt;But in your APPEND example the char_col has a value...?&lt;/P&gt;
&lt;P&gt;I think that&amp;nbsp;NUM and char MISSING&amp;nbsp;conversions is handled differently, since char MISSING is in fact a space, a valid char value. But the NUM MISSING can't be interpreted into a valid numerical value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I haven't worked with default&amp;nbsp;constraints in&amp;nbsp;DB2 (only in SQL Server), and then the case that the DBMS always set the default value. In your case it sounds like you are&amp;nbsp;trying to do a coalesce() type of logic. So have you tried the same logic within DB2?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 09:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235631#M6024</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-20T09:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Insert missing values into DB2</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235638#M6026</link>
      <description>&lt;P&gt;In the APPEND example I would have expected the data to be inserted successfully (since CHAR_COL has a value and NUM_COL should be assign it's default value). But this append fails since NUM_COL is missing.&lt;/P&gt;
&lt;PRE&gt;NOTE: Appending WORK.TO_BE_ACCEPTED to DB2DB.DBTABLE
NOTE: There were 1 observations read from the data set WORK.TO_BE_ACCEPTED.
NOTE: 0 observations added.
NOTE: The data set DB2DB.DBTABLE has . observations and 2 variables.
ERROR: CLI execute error: [IBM][CLI Driver][DB2/AIX64] SQL0407N  Assignment of a NULL value to a
       NOT NULL column "TBSPACEID=-6, TABLEID=-32265, COLNO=1" is not allowed.  SQLSTATE=23502
NOTE: Statements not processed because of errors noted above.&lt;/PRE&gt;
&lt;P&gt;Using this method, empty character values can be handled using e.g. the&amp;nbsp;NULLCHAR= data set option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if I don't supply the&amp;nbsp;num_col column DB2 does not assign the default value&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data to_be_accepted;
	char_col = 'aaa';
	output;
run;

proc datasets nolist;
	append base=db2db.db2table data=work.to_be_accepted nowarn force;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I simply want to insert one&amp;nbsp;character value into a two-columns table and letting the database set the other column's value to a default value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 10:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235638#M6026</guid>
      <dc:creator>Rikard</dc:creator>
      <dc:date>2015-11-20T10:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert missing values into DB2</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235644#M6027</link>
      <description>&lt;P&gt;If that's the case, it's sounds like the situation I described.&lt;/P&gt;
&lt;P&gt;We solved that issue by setting&amp;nbsp;&lt;SPAN&gt;IGNORE_READ_ONLY_COLUMNS=YES, which in out case made the columns under automatic constraints&amp;nbsp;be invisible for the SAS client, and not regarded&amp;nbsp;during insert/append operations.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 11:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Insert-missing-values-into-DB2/m-p/235644#M6027</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-20T11:53:24Z</dc:date>
    </item>
  </channel>
</rss>

