<?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: what is wrong with my code (calculating dates using intnx)? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589841#M14955</link>
    <description>So this works:&lt;BR /&gt;&lt;BR /&gt;where datepart(startdate) = '31AUG2018'd&lt;BR /&gt;&lt;BR /&gt;Why would you expect this to work:&lt;BR /&gt;&lt;BR /&gt;where datepart(startdate) = 31AUG2017&lt;BR /&gt;&lt;BR /&gt;Doesn't that look different?&lt;BR /&gt;&lt;BR /&gt;The second time around try:&lt;BR /&gt;&lt;BR /&gt;where datepart(startdate) = "&amp;amp;mydate"d</description>
    <pubDate>Wed, 18 Sep 2019 21:28:36 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-09-18T21:28:36Z</dc:date>
    <item>
      <title>what is wrong with my code (calculating dates using intnx)?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589835#M14953</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is a simplified version of my code.&amp;nbsp; what's wrong with it and how can I correct it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test(mydate);&lt;/P&gt;&lt;P&gt;%put 1 &amp;amp;mydate.;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select * from xx where datepart(startdate) = &amp;amp;mydate.; *&amp;amp;mydate evaluates to '31AUG2018'd ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* calculate 1 year prior */&lt;BR /&gt;%let mydate = %sysfunc(intnx(year,&amp;amp;mydate,-1,same), date9.);&lt;BR /&gt;%put 2 &amp;amp;mydate.;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select * from xx where datepart(startdate) = &amp;amp;mydate.; *&amp;amp;mydate evaluates to 31AUG2017 and doesn't work;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test('31AUG2018'd);&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 21:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589835#M14953</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-09-18T21:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with my code (calculating dates using intnx)?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589839#M14954</link>
      <description>&lt;P&gt;In the first case your macro variable's value looks like a date literal to SAS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'31AUG2018'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then your %LET statements make a value that does NOT look like a date literal&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;31AUG2018&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;So you either need to change how you USE the value in the second query.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example add back the quotes and the D suffix.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datepart(startdate) = "&amp;amp;mydate"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Or how change how you CREATE the new value.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You can make a date literal, like you passed in the macro call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mydate = "%sysfunc(intnx(year,&amp;amp;mydate,-1,same), date9.)"d ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just let the macro variable have the raw number of days since 1960 value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mydate = %sysfunc(intnx(year,&amp;amp;mydate,-1,same));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 21:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589839#M14954</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-18T21:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with my code (calculating dates using intnx)?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589841#M14955</link>
      <description>So this works:&lt;BR /&gt;&lt;BR /&gt;where datepart(startdate) = '31AUG2018'd&lt;BR /&gt;&lt;BR /&gt;Why would you expect this to work:&lt;BR /&gt;&lt;BR /&gt;where datepart(startdate) = 31AUG2017&lt;BR /&gt;&lt;BR /&gt;Doesn't that look different?&lt;BR /&gt;&lt;BR /&gt;The second time around try:&lt;BR /&gt;&lt;BR /&gt;where datepart(startdate) = "&amp;amp;mydate"d</description>
      <pubDate>Wed, 18 Sep 2019 21:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/589841#M14955</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-18T21:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with my code (calculating dates using intnx)?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/590033#M14985</link>
      <description>Thank you for the explanation. It's educational for me. I'm not an experienced SAS coder and still finding my way. Some people reply with condescending attitude.</description>
      <pubDate>Thu, 19 Sep 2019 14:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/what-is-wrong-with-my-code-calculating-dates-using-intnx/m-p/590033#M14985</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-09-19T14:17:07Z</dc:date>
    </item>
  </channel>
</rss>

