<?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: How to create  variable datetime field from sas date constant in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816234#M322139</link>
    <description>&lt;P&gt;I do not understand what it is that you are trying to do?&lt;/P&gt;
&lt;P&gt;Where are going to get a value for HOURS, MINUTES or SECONDS from a value that is only in DAYS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want to add some random number of seconds?&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 18:36:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-02T18:36:15Z</dc:date>
    <item>
      <title>How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816233#M322138</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have requirement to create a datetime variable consisting of different timestamp when run each time using a date constant field.&lt;/P&gt;&lt;P&gt;rundate='02JUN2022'd;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;rut=dhms(&amp;amp;rundate,hour(&amp;amp;rundate),minute(&amp;amp;rundate),second(&amp;amp;rundate));&lt;BR /&gt;call symput("ruts",rut);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;ruts.;&lt;/P&gt;&lt;P&gt;%let timest=%sysfunc(putn(&amp;amp;ruts,B8601DN8))%sysfunc(timepart(&amp;amp;ruts),B8601TM6);&lt;/P&gt;&lt;P&gt;%put &amp;amp;timest.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I run this query it create same timest value. I need to have different time value( hMS) when we run this query.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 18:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816233#M322138</guid>
      <dc:creator>sddxt</dc:creator>
      <dc:date>2022-06-02T18:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816234#M322139</link>
      <description>&lt;P&gt;I do not understand what it is that you are trying to do?&lt;/P&gt;
&lt;P&gt;Where are going to get a value for HOURS, MINUTES or SECONDS from a value that is only in DAYS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want to add some random number of seconds?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 18:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816234#M322139</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-02T18:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816235#M322140</link>
      <description>when i run the above query i get 20220602061958 in timest everytime I run the above query. I want the above query give me different minute and second value each run.&lt;BR /&gt;&lt;BR /&gt;Example: 20220602061958 last 4 digits should be different each time we run this.</description>
      <pubDate>Thu, 02 Jun 2022 18:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816235#M322140</guid>
      <dc:creator>sddxt</dc:creator>
      <dc:date>2022-06-02T18:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816237#M322141</link>
      <description>&lt;P&gt;What your code is doing is treating the numeric value of &amp;amp;rundate, which is a number of days, as time values with the hour, minute and second functions. Time values are numbers of seconds. So it is improper to really expect any useful result from that particular DHMS call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, provide what time of day you expect the result to be.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 18:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816237#M322141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-02T18:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816238#M322142</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/414329"&gt;@sddxt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I want the above query give me different minute and second value each run.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The obvious way to do this is to use the system clock — but you don't actually say that's what you want, and you still need to be more specific about how to obtain different hour minute second each time — well you don't even say you want different hours in each run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    rundate='02JUN2022'd;
    t=time();
    rut=dhms(rundate,hour(t),minute(t),second(t));
    call symput("ruts",rut);
run;

%put &amp;amp;ruts;
%put %sysfunc(putn(&amp;amp;ruts,datetime16.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 19:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816238#M322142</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-02T19:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816239#M322143</link>
      <description>Yes you are correct. So I need to have value generated which is combination of rundate&lt;BR /&gt;20220602 and randon hhMMSS combined together.&lt;BR /&gt;&lt;BR /&gt;which will give me value in timest as big number as 20220602061958 where HHMMSS change value with everyrun.</description>
      <pubDate>Thu, 02 Jun 2022 19:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816239#M322143</guid>
      <dc:creator>sddxt</dc:creator>
      <dc:date>2022-06-02T19:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816243#M322145</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/414329"&gt;@sddxt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes you are correct. So I need to have value generated which is combination of rundate&lt;BR /&gt;20220602 and randon hhMMSS combined together.&lt;BR /&gt;&lt;BR /&gt;which will give me value in timest as big number as 20220602061958 where HHMMSS change value with everyrun.
&lt;P class="1654197716390"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1654197716390"&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;okay, random times&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 _null_;
    rundate='02JUN2022'd;
    rut=86400*rundate+rand('uniform',0,86400);
    call symput("ruts",rut);
run;

%put &amp;amp;ruts;
%put %sysfunc(putn(&amp;amp;ruts,datetime19.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 19:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816243#M322145</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-02T19:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  variable datetime field from sas date constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816244#M322146</link>
      <description>&lt;P&gt;This generates a random time to add to the date.&lt;/P&gt;
&lt;PRE&gt;data _null_;
t = int(rand('uniform','00:00:00't,'23:59:59't));
rut=dhms(&amp;amp;rundate,0,0,t);
call symput("ruts",rut);
run;
 
%put &amp;amp;ruts;&lt;/PRE&gt;
&lt;P&gt;The INT function is to return integer portion as the rand function will return decimals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Any time you create macro variable from something numeric you need to take responsibility of the rules involved. If the values I used were not returning integers you could end up with a varying number of decimal places in that value.&lt;/P&gt;
&lt;P&gt;Also you want to consider using SYMPUTX instead of SYMPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 19:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-variable-datetime-field-from-sas-date-constant/m-p/816244#M322146</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-02T19:28:31Z</dc:date>
    </item>
  </channel>
</rss>

