<?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: Comparing against a DATETIME19 variable and macros in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Comparing-against-a-DATETIME19-variable-and-macros/m-p/942841#M42336</link>
    <description>&lt;P&gt;Why would you compare DATETIME values (number of seconds) to DATE values (number of days)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you are assuming that all of the dates are going to be in the 21st century?&lt;/P&gt;
&lt;P&gt;You can convert your four digit strings, like 2407, into a DATE value by using the INPUT() function (or in macro code using the %SYSFUNC() function to call the INPUTN() function) by prefixing it with 20 to set the century and suffixing it with 01 to set the day of the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_dt = 2407 ;
%let today = %sysfunc(inputn(20&amp;amp;curr_dt.01,yymmdd8.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can convert a DATE value into a DATETIME value by using the DHMS() function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now=%sysfunc(dhms(&amp;amp;today,0,0,0));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps by just multiplying by the number of seconds in a day.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now=%sysevalf(&amp;amp;today*'24:00:00't);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use INTNX() to find when the next month starts.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where ClosedDT &amp;gt;= &amp;amp;now
  and ClosedDt &amp;lt; %sysfunc(intnx(dtmonth,&amp;amp;now,1))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2024 03:17:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-09-06T03:17:03Z</dc:date>
    <item>
      <title>Comparing against a DATETIME19 variable and macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-against-a-DATETIME19-variable-and-macros/m-p/942825#M42333</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table that has a variable &lt;STRONG&gt;ClosedDt&amp;nbsp;&lt;/STRONG&gt;of types Num, Len 8, Format DATETIME19. and Informat DATETIME19.&lt;/P&gt;&lt;P&gt;I have a proc sql statement that would like to filter this table every month and this involves comparing against this variable. Could I please get some help on how best to write a simple macro variable to do this?&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Please see the below for what I mean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let curr_dt = 2407 /*this is in the form YYMM for month end*/


proc sql;
 create table output as
select a.CaseID as count_caseID
from source_data_&amp;amp;curr_dt. as a
where ClosedDt &amp;lt; "01AUG2024"d and ClosedDT &amp;gt;= "01JUL2024"d
;quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1. I know that the WHERE statement will produce zero observations. How can I rewrite it?&lt;/P&gt;&lt;P&gt;2. Could someone please show me how I can use the&amp;nbsp;&lt;STRONG&gt;curr_dt&lt;/STRONG&gt; macro variable to automate the WHERE statement (i.e. change the ClosedDt &amp;lt; "01AUG2024"d into something like ClosedDt &amp;lt; &amp;amp;dt_start. where&amp;nbsp;&lt;STRONG&gt;dt_start&lt;/STRONG&gt; will resolve to "01AUG2024", based on my&amp;nbsp;&lt;STRONG&gt;curr_dt&lt;/STRONG&gt; variable?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 00:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-against-a-DATETIME19-variable-and-macros/m-p/942825#M42333</guid>
      <dc:creator>newbatprocsql1</dc:creator>
      <dc:date>2024-09-06T00:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing against a DATETIME19 variable and macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-against-a-DATETIME19-variable-and-macros/m-p/942841#M42336</link>
      <description>&lt;P&gt;Why would you compare DATETIME values (number of seconds) to DATE values (number of days)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you are assuming that all of the dates are going to be in the 21st century?&lt;/P&gt;
&lt;P&gt;You can convert your four digit strings, like 2407, into a DATE value by using the INPUT() function (or in macro code using the %SYSFUNC() function to call the INPUTN() function) by prefixing it with 20 to set the century and suffixing it with 01 to set the day of the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_dt = 2407 ;
%let today = %sysfunc(inputn(20&amp;amp;curr_dt.01,yymmdd8.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can convert a DATE value into a DATETIME value by using the DHMS() function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now=%sysfunc(dhms(&amp;amp;today,0,0,0));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps by just multiplying by the number of seconds in a day.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now=%sysevalf(&amp;amp;today*'24:00:00't);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use INTNX() to find when the next month starts.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where ClosedDT &amp;gt;= &amp;amp;now
  and ClosedDt &amp;lt; %sysfunc(intnx(dtmonth,&amp;amp;now,1))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 03:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-against-a-DATETIME19-variable-and-macros/m-p/942841#M42336</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-06T03:17:03Z</dc:date>
    </item>
  </channel>
</rss>

