<?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: Creating a var using today's date Sas9.3 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871705#M344405</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133143"&gt;@Whitlea&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How would I do this if B_Date was in format datetime20. as well?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You would use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if b_date=. then ... ;&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;since a numeric variable missing value is indicated by a dot and not by " "&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 19:52:29 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-04-24T19:52:29Z</dc:date>
    <item>
      <title>Creating a var using today's date Sas9.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871675#M344384</link>
      <description>&lt;P&gt;I need to create a point in time variable in sas 9.3 using today's date where the date format in my data is datetime20.&lt;/P&gt;&lt;P&gt;I would like "today" to eq today's date.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Data WORK.want;&lt;BR /&gt;set WORK.want;&lt;BR /&gt;If A_Date &amp;gt; today then pt=0;&lt;BR /&gt;If B_Date=" " then pt=1;&lt;BR /&gt;If B_Date &amp;lt; today then pt=0;&lt;BR /&gt;If A_Date &amp;lt; today and B_Date =&amp;gt; today then pt=1;&lt;BR /&gt;else pt=0;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 17:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871675#M344384</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2023-04-24T17:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a var using today's date Sas9.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871680#M344386</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133143"&gt;@Whitlea&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to create a point in time variable in sas 9.3 using today's date where the date format in my data is datetime20.&lt;/P&gt;
&lt;P&gt;I would like "today" to eq today's date.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You would like TODAY to be equal to today's date, but your data is in format datetime20. This is a problem. It won't work the way you describe it. You can't directly compare a date to a datetime value. Instead, you want TODAY to be a datetime variable, most likely equal to 24APR2023:00:00:00. You can use the DATETIME() function and now you are comparing datetimes to datetimes, that will work. So the code would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data WORK.want1;
    set WORK.want;
    today=datetime(); /* Now today is a datetime variable */
    if A_Date &amp;gt; today then pt=0;
    if B_Date=" " then pt=1; /* This won't work if b_date is a numeric datetime variable, are you sure it is a numeric datetime variable? */
    If B_Date &amp;lt; today then pt=0;
    If A_Date &amp;lt; today and B_Date =&amp;gt; today then pt=1;
    else pt=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;As an alternative, you can do this which will compare dates to dates (using the DATEPART function to turn datetimes into dates):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data WORK.want1;
    set WORK.want;
    today=today(); /* Now today is a date variable */
    /* You can't directly compare a datetime variable like A_DATE to a DATE Variable */
    /* But the datepart function turns a datetime variable into a date variable which can be compared to a date variable */
    If datepart(A_Date) &amp;gt; today then pt=0;
    If datepart(B_Date)=" " then pt=1; /* This won't work if b_date is a numeric datetime variable, are you sure it is a numeric datetime variable? */
    If datepart(B_Date) &amp;lt; today then pt=0;
    If datepart(A_Date) &amp;lt; today and datepart(B_Date) =&amp;gt; today then pt=1;
    else pt=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 18:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871680#M344386</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-24T18:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a var using today's date Sas9.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871701#M344401</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How would I do this if B_Date was in format datetime20. as well?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871701#M344401</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2023-04-24T19:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a var using today's date Sas9.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871705#M344405</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133143"&gt;@Whitlea&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How would I do this if B_Date was in format datetime20. as well?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You would use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if b_date=. then ... ;&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;since a numeric variable missing value is indicated by a dot and not by " "&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-var-using-today-s-date-Sas9-3/m-p/871705#M344405</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-24T19:52:29Z</dc:date>
    </item>
  </channel>
</rss>

