<?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 Unable to append Dates (YYMMDD10.) to sql table in stg schema in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928341#M365244</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am&amp;nbsp; trying to use SAS to append a dataset into a SQL table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using this code (modified the table names). My dates are in YYDDMM10. format, numeric = type, length = 8, informat =10. and they cannot be appended because of type of mismatch. The variables in the SQL table is set to the data type = "date" and it has allow nulls checked off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help is appreciated!! &amp;gt;.&amp;lt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname Dummy odbc dsn='Dummy_data' schema=stg;




data org.procedures;
set procedures;
RunDate = today();
format RunDate date9.;
if firstobs then Obs_ID = 1;
else Obs_ID +1;
run;


*remove exisiting data from table;
data Dummy.data_Numerators; 
modify Dummy.data_Numerators;
if Obs_ID not = '.0y' then
remove Dummy.data_Numerators;
run;

*append new data to table;
proc append data= org.procedures base = Dummy.data_Numerators force; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scooby3g_0-1715705579343.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96528iB4D5BDBDF20CF446/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scooby3g_0-1715705579343.png" alt="Scooby3g_0-1715705579343.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scooby3g_1-1715705589705.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96529i5D2EC28EB04750E8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scooby3g_1-1715705589705.png" alt="Scooby3g_1-1715705589705.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 May 2024 17:01:22 GMT</pubDate>
    <dc:creator>Scooby3g</dc:creator>
    <dc:date>2024-05-14T17:01:22Z</dc:date>
    <item>
      <title>Unable to append Dates (YYMMDD10.) to sql table in stg schema</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928341#M365244</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am&amp;nbsp; trying to use SAS to append a dataset into a SQL table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using this code (modified the table names). My dates are in YYDDMM10. format, numeric = type, length = 8, informat =10. and they cannot be appended because of type of mismatch. The variables in the SQL table is set to the data type = "date" and it has allow nulls checked off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help is appreciated!! &amp;gt;.&amp;lt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname Dummy odbc dsn='Dummy_data' schema=stg;




data org.procedures;
set procedures;
RunDate = today();
format RunDate date9.;
if firstobs then Obs_ID = 1;
else Obs_ID +1;
run;


*remove exisiting data from table;
data Dummy.data_Numerators; 
modify Dummy.data_Numerators;
if Obs_ID not = '.0y' then
remove Dummy.data_Numerators;
run;

*append new data to table;
proc append data= org.procedures base = Dummy.data_Numerators force; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scooby3g_0-1715705579343.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96528iB4D5BDBDF20CF446/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scooby3g_0-1715705579343.png" alt="Scooby3g_0-1715705579343.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scooby3g_1-1715705589705.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96529i5D2EC28EB04750E8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scooby3g_1-1715705589705.png" alt="Scooby3g_1-1715705589705.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 17:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928341#M365244</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2024-05-14T17:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to append Dates (YYMMDD10.) to sql table in stg schema</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928383#M365257</link>
      <description>&lt;P&gt;Datetime values in SAS are numbers of seconds. I would expect something with a datetime format to be such.&lt;/P&gt;
&lt;P&gt;Date values in SAS are numbers of DAYs. So any combining of data sets or use needs to keep that in mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can turn a Date value into a datetime with something like this:&lt;/P&gt;
&lt;PRE&gt;dt_from_date = dhms(datevariable,0,0,0);&lt;/PRE&gt;
&lt;P&gt;which assigns the hour, minute and second component of a datetime as 0 for the given date.&lt;/P&gt;
&lt;P&gt;OR get the Date value from a datetime using:&lt;/P&gt;
&lt;PRE&gt;datevalue = datepart( datetimevariable);&lt;/PRE&gt;
&lt;P&gt;so you could append dates to dates or datetimes to datetimes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;HOWEVER,&amp;nbsp;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;this statement : "My dates are in YYDDMM10. format, numeric = type, length = 8, informat =10" al&lt;FONT color="#000000"&gt;most certainly means that your values are not actually dates either. I would guess that you have a numeric value that you imagine is a data such as 20240510 and think that is "10 May 2024". &lt;FONT color="#000000"&gt;If you attempt to treat a number like 20240510 as a date you will find that is much larger&lt;FONT color="#000000"&gt; tha&lt;FONT color="#000000"&gt;n the largest date value&lt;FONT color="#000000"&gt; SAS currently supports whic&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;h is 6589336 or 31Dec20000 (yes year 20K).&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;So if you want a SAS date value of 10 May 2024 you need to either read from an external source with an informat like YYMMDD10 or convert your value:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20240510;
   date = input(put(x,8.),yymmdd10.);
   format date yymmdd10.;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Then use the DHMS function to create a datetime value.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Then append the data.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Caution: I have never used STG through ODBC links. I am not sure that the approach you have attempted with MODIFY will work. You may need to create a temporary SAS data set with similar code:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;data work.data_Numerators; 
set Dummy.data_Numerators;
if Obs_ID not = '.0y' then delete;

run;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Append you data to this SAS data set. Then write it back to the Dummy library.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;BR /&gt;&lt;/FONT&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 20:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928383#M365257</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-14T20:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to append Dates (YYMMDD10.) to sql table in stg schema</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928390#M365262</link>
      <description>&lt;P&gt;Run PROC CONTENTS on both datasets, then take appropriate action so that the append dataset's variable attributes matches those of the base dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 21:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928390#M365262</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-05-14T21:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to append Dates (YYMMDD10.) to sql table in stg schema</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928419#M365278</link>
      <description>&lt;P&gt;What the warning tells you is that the data type on the SQL Server side must be Datetime or Datetime2 but that on the SAS side the variable uses a Date and not a Datetime format. The code you shared also shows that the variable on the SAS side stores a SAS Date (count of days since 1/1/1960) and not a SAS Datetime value (count of seconds since 1/1/1960).&lt;/P&gt;
&lt;P&gt;This section&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0h4i25zq3t58en1lgr8jjx1rads.htm" target="_self"&gt;LIBNAME Statement Data Conversions&lt;/A&gt;&amp;nbsp;under the doc for the SQL Server access engine shows you how SAS and SQL Server column types map to each other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you populate and format your variable in your data step as a SAS datetime column then things will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data org.procedures;
  set procedures;
  RunDate = DATETIME();
  format RunDate DATETIME22.;
  if firstobs then
    Obs_ID = 1;
  else Obs_ID +1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 01:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-append-Dates-YYMMDD10-to-sql-table-in-stg-schema/m-p/928419#M365278</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-15T01:34:46Z</dc:date>
    </item>
  </channel>
</rss>

