<?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: Use of datetime() function in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/440164#M282412</link>
    <description>&lt;P&gt;Thanks to all who replied. It was the CONSTDATETIME option I was looking for.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2018 12:22:40 GMT</pubDate>
    <dc:creator>lethcons</dc:creator>
    <dc:date>2018-02-26T12:22:40Z</dc:date>
    <item>
      <title>Use of datetime() function in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439365#M282407</link>
      <description>&lt;P&gt;Consider this:&lt;/P&gt;&lt;PRE&gt;proc sql;
insert into mysastab(key, datetime)
select key,
       datetime()
from mysastab0
;
quit;&lt;/PRE&gt;&lt;P&gt;I think I may have heard that the datetime() function gets evaluated once and then that constant value is used for each row inserted into mysastab from mysastab0. I want to avoid the situation where the value for datetime is evaluated for every input row and so may not show exactly the same time for each row inserted.&lt;/P&gt;&lt;P&gt;Which is it? Can anyone give an authoritative answer?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 16:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439365#M282407</guid>
      <dc:creator>lethcons</dc:creator>
      <dc:date>2018-02-22T16:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use of datetime() function in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439409#M282408</link>
      <description>&lt;P&gt;If I do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data my_sas_table;
   input key mydatetime datetime.;
datalines;
1 01jan2018:16:24:43.43
2 01jan2018:16:24:43.43
3 01jan2018:16:24:43.43
4 01jan2018:16:24:43.43
5 01jan2018:16:24:43.43
6 01jan2018:16:24:43.43
7 01jan2018:16:24:43.43
;
run;

proc sql;
create table two_my_sas_table (key numeric, mydatetime date);
insert into two_my_sas_table (key, mydatetime)
select key, datetime()
from my_sas_table;
quit;

proc print noobs;
format mydatetime datetime.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    The SAS System      16:16 Tuesday, February 20, 2018  27

                                     key       mydatetime

                                      1     22FEB18:12:57:24
                                      2     22FEB18:12:57:24
                                      3     22FEB18:12:57:24
                                      4     22FEB18:12:57:24
                                      5     22FEB18:12:57:24
                                      6     22FEB18:12:57:24
                                      7     22FEB18:12:57:24&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suggesting that the inserted times are the same.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 19:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439409#M282408</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-02-22T19:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use of datetime() function in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439447#M282409</link>
      <description>&lt;P&gt;Proc SQL has the&amp;nbsp;NOCONSTDATETIME option, this will control, whether the today() or datetime() function are evaluated once or every time. To be on the save side, I suggest to use a macro expression like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc( datetime() )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;this will be evaluated only once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See also this code sample&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
  do i = 1 to 1e5;
    output;
  end;
run;

proc sql noconstdatetime;
  drop table two_my_sas_table;
  create table two_my_sas_table (
    key numeric
    , mydatetime numeric format=datetime23.3
    , mydatetime2 numeric format=datetime23.3
    );
  insert into two_my_sas_table 
    select i, datetime(), %sysfunc( datetime() )
      from long
  ;
quit;

proc freq data=work.two_my_sas_table;
  table mydatetime mydatetime2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Feb 2018 20:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439447#M282409</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-02-22T20:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use of datetime() function in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439588#M282410</link>
      <description>&lt;P&gt;OR use system macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
  do i = 1 to 10;
    output;
  end;
run;

proc sql noconstdatetime;
  drop table two_my_sas_table;
  create table two_my_sas_table (
    key numeric
    , mydatetime numeric format=datetime23.3
    , mydatetime2 numeric format=datetime23.3
    );
  insert into two_my_sas_table 
    select i, datetime(), dhms("&amp;amp;sysdate"d,0,0,"&amp;amp;systime"t)
      from long
  ;
quit;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Feb 2018 04:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439588#M282410</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-23T04:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Use of datetime() function in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439633#M282411</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134349"&gt;@lethcons&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The SQL FEEDBACK option will tell you what's fact. Default is a constant value.&lt;/P&gt;
&lt;PRE&gt;40         proc sql feedback;
41           insert into mysastab(key, datetime)
42             select key,
43               datetime()
44             from mysastab0
45           ;
NOTE: Statement transforms to:

        insert
          into WORK.MYSASTAB(MYSASTAB.key, MYSASTAB.datetime)
        select MYSASTAB0.key, '  23FEB2018:20:16:12'DT
          from WORK.MYSASTAB0;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Feb 2018 09:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/439633#M282411</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-02-23T09:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Use of datetime() function in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/440164#M282412</link>
      <description>&lt;P&gt;Thanks to all who replied. It was the CONSTDATETIME option I was looking for.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 12:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-datetime-function-in-SQL/m-p/440164#M282412</guid>
      <dc:creator>lethcons</dc:creator>
      <dc:date>2018-02-26T12:22:40Z</dc:date>
    </item>
  </channel>
</rss>

