<?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 Adding the number of days to a date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903946#M40351</link>
    <description>&lt;P&gt;Hi experts,&lt;/P&gt;
&lt;P&gt;I have used a code to add the number of days to a date. I want the output data to add the number of days and give me a new column which shows the new_date but when I use the code, it add the number of days in time as I am using datetime format. Please see the sample dataset and suggest what can I do so that sas code adds the number of days and give the new date. If you observe the below data, the new_date constains the same date and&amp;nbsp;dt_datdelay is added as time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data delayed_accounts;				
infile cards expandtabs;				
input debt_code	rep_code$	dt_delaydays	dt_datdelay:datetime22.3 new_date:datetime22.3;
format dt_datdelay datetime22.3 new_date:datetime22.3;
datalines ;	
106444375	133	16	21MAR2013:00:00:00.000	21MAR2013:00:00:16.000
345347595	168	2	23DEC2019:00:00:00.000	23DEC2019:00:00:02.000
323832873	168C	10	24FEB2020:00:00:00.000	24FEB2020:00:00:10.000
178669982	122	30	06SEP2017:00:00:00.000	06SEP2017:00:00:30.000
;				
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
create table delayed_accounts as
select *,
dt_delaydays + dt_datdelay as new_date format datetime22.3
from Accounts_in_trace;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 Nov 2023 15:58:25 GMT</pubDate>
    <dc:creator>Sandeep77</dc:creator>
    <dc:date>2023-11-20T15:58:25Z</dc:date>
    <item>
      <title>Adding the number of days to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903946#M40351</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
&lt;P&gt;I have used a code to add the number of days to a date. I want the output data to add the number of days and give me a new column which shows the new_date but when I use the code, it add the number of days in time as I am using datetime format. Please see the sample dataset and suggest what can I do so that sas code adds the number of days and give the new date. If you observe the below data, the new_date constains the same date and&amp;nbsp;dt_datdelay is added as time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data delayed_accounts;				
infile cards expandtabs;				
input debt_code	rep_code$	dt_delaydays	dt_datdelay:datetime22.3 new_date:datetime22.3;
format dt_datdelay datetime22.3 new_date:datetime22.3;
datalines ;	
106444375	133	16	21MAR2013:00:00:00.000	21MAR2013:00:00:16.000
345347595	168	2	23DEC2019:00:00:00.000	23DEC2019:00:00:02.000
323832873	168C	10	24FEB2020:00:00:00.000	24FEB2020:00:00:10.000
178669982	122	30	06SEP2017:00:00:00.000	06SEP2017:00:00:30.000
;				
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
create table delayed_accounts as
select *,
dt_delaydays + dt_datdelay as new_date format datetime22.3
from Accounts_in_trace;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 15:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903946#M40351</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-11-20T15:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the number of days to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903951#M40353</link>
      <description>&lt;P&gt;Write this down (in handwriting!) 100 times:&lt;/P&gt;
&lt;P&gt;SAS dates are counts of days, SAS datetimes and times are cou nts of seconds!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should let the message sink in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In add a number of days to a datetime, you either add 86400 (the number of seconds in a day) * number of days, or you use the INTNX function, which gives you the additional advantage that you can align the result to specific timepoints within the given interval.&lt;/P&gt;
&lt;P&gt;The interval you want to use is DTDAY (DAY is for dates).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table delayed_accounts as
  select
    *,
    intnx("dtday",dt_datdelay,dt_delaydays,"s") as new_date format datetime22.3
  from accounts_in_trace
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you used "B" or "E" instead of the "S", you'd get the beginning or end of the day.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903951#M40353</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-20T16:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the number of days to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903952#M40354</link>
      <description>&lt;P&gt;Dates are stored in days, but datetimes are stored in seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the INTNX() function to move date/time/datetime values by intervals that are not in the units used to store the values.&amp;nbsp; Datetime intervals have DT prefixed to their names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table delayed_accounts as
  select *
   , intnx('dtday',dt_datdelay,dt_delaydays,'same') as new_date format datetime22.3
  from Accounts_in_trace
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want to use addition then multiple days by 24 hours worth of seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,dt_datdelay + dt_delaydays*'24:00:00't as new_date format datetime22.3
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-the-number-of-days-to-a-date/m-p/903952#M40354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-20T16:11:16Z</dc:date>
    </item>
  </channel>
</rss>

