<?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: SAS date  and time  codnitions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841027#M332531</link>
    <description>I think you need to be using the time_new variable you created in the last step, not the time variable. The time_new is the sas time which should give you want.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 26 Oct 2022 20:39:06 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-10-26T20:39:06Z</dc:date>
    <item>
      <title>SAS date  and time  codnitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841019#M332525</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set that contain 2 fields:&amp;nbsp; &amp;nbsp;date (sas date) and time (numeric time).&lt;/P&gt;
&lt;P&gt;I converted the numeric time into sas time and then created a new field of date+time (in date time format).&lt;/P&gt;
&lt;P&gt;Now is coming my question:&lt;/P&gt;
&lt;P&gt;I want to create a new date field called "calc_new_date"&amp;nbsp; that will be a sas data and will get following value:&lt;/P&gt;
&lt;P&gt;IF the time greater&amp;nbsp; equal&amp;nbsp; 24:01 and lower&amp;nbsp; equal 18:29&amp;nbsp; then&amp;nbsp;calc_new_date will be equal to date.&lt;/P&gt;
&lt;P&gt;Else IF time greater equal&amp;nbsp; 18:30 and&amp;nbsp; lower equal&amp;nbsp; 23:59 then&amp;nbsp;calc_new_date will be equal to date+1.&lt;/P&gt;
&lt;P&gt;(In other words, if time is later than 18:30 then calc_new_date will be one day after date)&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;Here is my tempt to do it&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data have;
format date date9.;
Input date : date9. time;
cards;
'19OCT2022'd 90200
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 181400
'19OCT2022'd 160300
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 113400
'19OCT2022'd 0
'19OCT2022'd 85700
'19OCT2022'd 0
'19OCT2022'd 0
'20OCT2022'd 93800
'20OCT2022'd 93700
'20OCT2022'd 114600
'20OCT2022'd 0
'21OCT2022'd 0
'21OCT2022'd 85900
'21OCT2022'd 0
'21OCT2022'd 94100
;
Run;


data have2;
set have;
time_=put(time,z6.);
time_new=input(time_,hhmmss6.);
date_time=dhms(date, 0, 0,time_new);
Format time_new hhmm.  date_time datetime20. date date9.;
drop  time_;
Run;


data want;
set have2;
IF  time&amp;gt;='24:01:00't  and time&amp;lt;='18:29:00't then calc_new_Date=date;
else IF time&amp;gt;='18:30:00't and time&amp;lt;'23:59:00't then calc_new_Date=date+1;
format calc_new_Date  date9.;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841019#M332525</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-10-26T20:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date  and time  codnitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841027#M332531</link>
      <description>I think you need to be using the time_new variable you created in the last step, not the time variable. The time_new is the sas time which should give you want.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841027#M332531</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-26T20:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date  and time  codnitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841028#M332532</link>
      <description>&lt;P&gt;Does "time greater equal 24:01" refer to 24 minutes after the hour? In a date time value you can't have time greater than hour 24 and is a poor idea with clock times as you should never have anything greater than 24:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your time comparison codes actually leave out a fair amount of time.&lt;/P&gt;
&lt;P&gt;Since your example data does not include any times after 18:30 how are we supposed to test that part??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this is correct for some added times after 18:30:00&lt;/P&gt;
&lt;PRE&gt;Data have;
format date date9.;
Input date : date9. time;
cards;
'19OCT2022'd 90200
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 201500
'19OCT2022'd 0
'19OCT2022'd 181400
'19OCT2022'd 160300
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 113400
'19OCT2022'd 0
'19OCT2022'd 85700
'19OCT2022'd 0
'19OCT2022'd 0
'20OCT2022'd 93800
'20OCT2022'd 93700
'20OCT2022'd 114600
'20OCT2022'd 212000
'21OCT2022'd 0
'21OCT2022'd 85900
'21OCT2022'd 0
'21OCT2022'd 94100
;
Run;


data have2;
set have;
time_=put(time,z6.);
time_new=input(time_,hhmmss6.);
date_time=dhms(date, 0, 0,time_new);
Format time_new hhmm.  date_time datetime20. date date9.;
drop  time_;
Run;


data want;
set have2;&lt;BR /&gt;/* edited to use correct time variable
&lt;STRIKE&gt;IF '00:00:00't&amp;lt;= time &amp;lt;'18:30:00't then calc_new_Date=date;&lt;BR /&gt;*/&lt;/STRIKE&gt;&lt;BR /&gt;IF '00:00:00't&amp;lt;= time_new &amp;lt;'18:30:00't then calc_new_Date=date;
else  calc_new_Date=date+1;
format calc_new_Date  date9.;
Run;&lt;/PRE&gt;
&lt;P&gt;BTW, your data step does not need the quotes and D in the datalines&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set that contain 2 fields:&amp;nbsp; &amp;nbsp;date (sas date) and time (numeric time).&lt;/P&gt;
&lt;P&gt;I converted the numeric time into sas time and then created a new field of date+time (in date time format).&lt;/P&gt;
&lt;P&gt;Now is coming my question:&lt;/P&gt;
&lt;P&gt;I want to create a new date field called "calc_new_date"&amp;nbsp; that will be a sas data and will get following value:&lt;/P&gt;
&lt;P&gt;IF the time greater&amp;nbsp; equal&amp;nbsp; 24:01 and lower&amp;nbsp; equal 18:29&amp;nbsp; then&amp;nbsp;calc_new_date will be equal to date.&lt;/P&gt;
&lt;P&gt;Else IF time greater equal&amp;nbsp; 18:30 and&amp;nbsp; lower equal&amp;nbsp; 23:59 then&amp;nbsp;calc_new_date will be equal to date+1.&lt;/P&gt;
&lt;P&gt;(In other words, if time is later than 18:30 then calc_new_date will be one day after date)&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;Here is my tempt to do it&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data have;
format date date9.;
Input date : date9. time;
cards;
'19OCT2022'd 90200
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 181400
'19OCT2022'd 160300
'19OCT2022'd 0
'19OCT2022'd 0
'19OCT2022'd 113400
'19OCT2022'd 0
'19OCT2022'd 85700
'19OCT2022'd 0
'19OCT2022'd 0
'20OCT2022'd 93800
'20OCT2022'd 93700
'20OCT2022'd 114600
'20OCT2022'd 0
'21OCT2022'd 0
'21OCT2022'd 85900
'21OCT2022'd 0
'21OCT2022'd 94100
;
Run;


data have2;
set have;
time_=put(time,z6.);
time_new=input(time_,hhmmss6.);
date_time=dhms(date, 0, 0,time_new);
Format time_new hhmm.  date_time datetime20. date date9.;
drop  time_;
Run;


data want;
set have2;
IF  time&amp;gt;='24:01:00't  and time&amp;lt;='18:29:00't then calc_new_Date=date;
else IF time&amp;gt;='18:30:00't and time&amp;lt;'23:59:00't then calc_new_Date=date+1;
format calc_new_Date  date9.;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 21:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841028#M332532</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-26T21:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date  and time  codnitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841032#M332536</link>
      <description>&lt;P&gt;So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;code runs, but it should still be time_new not time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Time is numeric so SAS will convert it to a time but it's not doing the correct calculations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to change the variable name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-time-codnitions/m-p/841032#M332536</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-26T20:55:12Z</dc:date>
    </item>
  </channel>
</rss>

