<?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 use intnx on datetime function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686596#M208388</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349066"&gt;@Learn_SAS1&lt;/a&gt;&amp;nbsp; Please try using 'dtmonth' as the interval instead of month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('dtmonth',Your_datetime_var,-1,'same')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;dtmonth should&amp;nbsp;&lt;SPAN&gt;work for datetime values.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Sep 2020 02:38:23 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-09-25T02:38:23Z</dc:date>
    <item>
      <title>How to use intnx on datetime function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686589#M208383</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to use intnx on my date variable which is in the dateampm format.&lt;/P&gt;&lt;P&gt;My date variable has the value of "31Dec14:00:00:00"&lt;/P&gt;&lt;P&gt;I want to use the below code example.&lt;/P&gt;&lt;P&gt;Data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;set callsymput('date1',put(intnx('month',today(),-1,'same'),date9.);&amp;nbsp;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;but when I use on my dataset date variable as mentioned below&lt;/P&gt;&lt;P&gt;date&amp;gt;"&amp;amp;date1". resulting 0 records even if there are records. Reason, it is in date time format.&lt;/P&gt;&lt;P&gt;Can someone help me how to use call symput on datetime variables&lt;/P&gt;&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 01:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686589#M208383</guid>
      <dc:creator>Learn_SAS1</dc:creator>
      <dc:date>2020-09-25T01:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use intnx on datetime function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686596#M208388</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349066"&gt;@Learn_SAS1&lt;/a&gt;&amp;nbsp; Please try using 'dtmonth' as the interval instead of month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('dtmonth',Your_datetime_var,-1,'same')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;dtmonth should&amp;nbsp;&lt;SPAN&gt;work for datetime values.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 02:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686596#M208388</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-09-25T02:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use intnx on datetime function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686598#M208390</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349066"&gt;@Learn_SAS1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to use intnx on my date variable which is in the dateampm format.&lt;/P&gt;
&lt;P&gt;My date variable has the value of "31Dec14:00:00:00"&lt;/P&gt;
&lt;P&gt;I want to use the below code example.&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set callsymput('date1',put(intnx('month',today(),-1,'same'),date9.);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;but when I use on my dataset date variable as mentioned below&lt;/P&gt;
&lt;P&gt;date&amp;gt;"&amp;amp;date1". resulting 0 records even if there are records. Reason, it is in date time format.&lt;/P&gt;
&lt;P&gt;Can someone help me how to use call symput on datetime variables&lt;/P&gt;
&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have no idea what you are doing here.&lt;/P&gt;
&lt;P&gt;1. SET expects a data set name&lt;/P&gt;
&lt;P&gt;2. callsymput() does not exist&lt;/P&gt;
&lt;P&gt;3. There is no variable DATE anywhere&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;4. You cannot use date and datetime values in the same operation. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp; Either everything is date (and the interval is for example&amp;nbsp;&lt;EM&gt;month&lt;/EM&gt;)&amp;nbsp; or everything is datetime (and the interval is for example&amp;nbsp;&lt;EM&gt;dtmonth&lt;/EM&gt;).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 02:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686598#M208390</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-25T02:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use intnx on datetime function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686717#M208433</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349066"&gt;@Learn_SAS1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to use intnx on my date variable which is in the dateampm format.&lt;/P&gt;
&lt;P&gt;My date variable has the value of "31Dec14:00:00:00"&lt;/P&gt;
&lt;P&gt;I want to use the below code example.&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set callsymput('date1',put(intnx('month',today(),-1,'same'),date9.);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;but when I use on my dataset date variable as mentioned below&lt;/P&gt;
&lt;P&gt;date&amp;gt;"&amp;amp;date1". resulting 0 records even if there are records. Reason, it is in date time format.&lt;/P&gt;
&lt;P&gt;Can someone help me how to use call symput on datetime variables&lt;/P&gt;
&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your value, if it has date and time components, is a DATETIME variable, not a Date. As such Date intervals cannot be used and get any expected result as the base units between Dates, days, and Datetime, seconds, are not compatible.&lt;/P&gt;
&lt;P&gt;The intervals involving the date portion of a datetime variable in the Intnx or Intck functions start with DT, such as Dtday, Dtmonth, Dtquarter, Dtweek, Dtyear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you compare dates to datetimes directly you very seldom get the correct result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If Date is numeric this will fail with your attempt:&lt;/P&gt;
&lt;P&gt;date&amp;gt;"&amp;amp;date1".&lt;/P&gt;
&lt;P&gt;because, since attempted to apply a Format to the macro variable would be comparing a number to a value like "10SEP2020". SAS will attempt to convert strings to numbers or vice versa for comparisons but the macro variable AS FORMATTED can't be converted. If you intend to use a date literal it would have to have a d after the value as in "10SEP2020"d to be used as a date value. See the comparison of date and datetime again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you have some code that worked before attempting this macro variable solution? If so, show an example. That is the first step: get code working without macro variables &lt;STRONG&gt;before&lt;/STRONG&gt; creating the first macro variable. Then you know what your macro variable should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better to leave the macro variable as the numeric value instead of the formatted date/datetime/time unless you are using the value to write human readable text such as titles to simplify the code.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 14:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-intnx-on-datetime-function/m-p/686717#M208433</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-25T14:57:01Z</dc:date>
    </item>
  </channel>
</rss>

