<?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: macro varible (date) in proc sql in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685365#M24295</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52150"&gt;@rajeshm&lt;/a&gt;&amp;nbsp;, we discussed this and answered your question in your thread last week at&amp;nbsp;&lt;A href="https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684647" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684647&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DO NOT FORMAT MACRO VARIABLES&lt;/P&gt;</description>
    <pubDate>Mon, 21 Sep 2020 10:54:58 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-21T10:54:58Z</dc:date>
    <item>
      <title>macro date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684647#M24217</link>
      <description>&lt;PRE&gt;&lt;BR /&gt;%let pre_first_date = %str(%')%sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, begin)), date9.))%str(%');&lt;BR /&gt;%let pre_last_date = %str(%')%sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, end)), date9.))%str(%');&lt;BR /&gt;%let d_pre_first_date =%str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1)),date9.))%str(%')d;&lt;BR /&gt;%let d_pre_last_date =%str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,end)),date9.))%str(%')d;&lt;BR /&gt;%put &amp;amp;pre_first_date &amp;amp;d_pre_last_date;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table xxx as&lt;BR /&gt;select&lt;BR /&gt;zz&lt;BR /&gt;from mytablexxx&lt;BR /&gt;/* option1 where po_date between &amp;amp;d_pre_first_date and &amp;amp;d_pre_last_date;--not working*/&lt;BR /&gt;/*option2 where po_date between "&amp;amp;d_pre_first_date." and "&amp;amp;d_pre_last_date.";ERROR: Expression using IN has components that are of different data types.*/&lt;BR /&gt;where po_date between "&amp;amp;pre_first_date."d and "&amp;amp;pre_last_date."d;/* working fine */&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;I am so sorry for posting partial data in my earlier mail,plsconsider that let me know why first and second options are not working.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 16:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684647#M24217</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-09-17T16:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: macro date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684654#M24218</link>
      <description>&lt;P&gt;You are overcomplicating things by miles, for no reason at all.&lt;/P&gt;
&lt;P&gt;See Maxim 28: Macro Variables Need No Format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pre_first_date = %sysfunc(intnx(month,%sysfunc(today()),-1,begin));
%let d_pre_last_date = %sysfunc(intnx(month,%sysfunc(today()),-1,end));

where post_date between &amp;amp;pre_first_date. and &amp;amp;d_pre_last_date.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 15:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684654#M24218</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-17T15:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: macro date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684656#M24219</link>
      <description>&lt;P&gt;You are working very hard to perform tasks that should be avoided, and also violates &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;. Macro variables should not be formatted!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pre_first_date = %sysfunc(intnx(month, %sysfunc(today()), -1, begin));
%let d_pre_last_date =%sysfunc(intnx(month,%sysfunc(today()),-1,end));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where post_date between &amp;amp;pre_first_date and &amp;amp;d_pre_last_date &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Much simpler!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(The only time you need to format macro variables is in titles or labels, but macro variables should not be formatted in arithmetic or boolean expressions).&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 15:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684656#M24219</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-17T15:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684658#M24220</link>
      <description>&lt;P&gt;Your problem was exactly this: text replacement. Insert the created macro variables within the double quotes, and you get&lt;/P&gt;
&lt;PRE&gt;"'01AUG2020'"d&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;"'31AUG2020'd"d&lt;/PRE&gt;
&lt;P&gt;which both are, very obviously, not SAS date literals.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 15:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684658#M24220</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-17T15:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: macro date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684659#M24221</link>
      <description>&lt;P&gt;First lets discuss what youi think the variable&lt;/P&gt;
&lt;PRE&gt;&amp;amp;pre_first_date.&lt;/PRE&gt;
&lt;P&gt;Should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then run this and look in the log:&lt;/P&gt;
&lt;PRE&gt;%put &amp;amp;pre_first_date.;
&lt;/PRE&gt;
&lt;P&gt;Which will show something like&lt;/P&gt;
&lt;PRE&gt;'01AUG2020'
&lt;/PRE&gt;
&lt;P&gt;So when you use&lt;/P&gt;
&lt;PRE&gt;where post_date between "&amp;amp;pre_first_date."d &lt;/PRE&gt;
&lt;P&gt;When the macro variable resolves generates&lt;/P&gt;
&lt;PRE&gt;where post_date between "'01AUG2020'"d &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Hint: there are too many quotes.&lt;/P&gt;
&lt;P&gt;So remove your forced quotes in the macro variable. Unless you are using the same variable to also create human readable text like a title or the name of an output file you would be better off with&lt;/P&gt;
&lt;PRE&gt;%let pre_first_date = %sysfunc(intnx(month, %sysfunc(today()), -1, begin));
/* same for the other bound*/
/* and use*/
where post_date between &amp;amp;pre_first_date. and &amp;amp;d_pre_last_date &lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 15:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684659#M24221</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-17T15:16:42Z</dc:date>
    </item>
    <item>
      <title>macro varible (date) in proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685351#M24294</link>
      <description>&lt;P&gt;this is similar to my previous code but no one replied after edit my post.&lt;/P&gt;
&lt;P&gt;how to avoid hardcoding d in this&amp;nbsp;&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;"&amp;amp;pre_first_date."d&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;%let pre_first_date = %str(%')%sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, begin)), date9.))%str(%');&lt;BR /&gt;%let pre_last_date = %str(%')%sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, end)), date9.))%str(%');&lt;BR /&gt;%let d_pre_first_date =%str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1)),date9.))%str(%')d;&lt;BR /&gt;%let d_pre_last_date =%str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,end)),date9.))%str(%')d;&lt;BR /&gt;%put &amp;amp;pre_first_date &amp;amp;d_pre_last_date;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;create table xxx as&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;select&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;zz&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from mytablexxx&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;/* option1 where po_date between &amp;amp;d_pre_first_date and &amp;amp;d_pre_last_date;--not working*/&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;/*option2 where po_date between "&amp;amp;d_pre_first_date." and "&amp;amp;d_pre_last_date.";ERROR: Expression using IN has components that are of different data types.*/&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;where po_date between "&amp;amp;pre_first_date."d and "&amp;amp;pre_last_date."d;/* working fine but how can i avoid hardcoding d here */&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 09:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685351#M24294</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-09-21T09:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: macro varible (date) in proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685365#M24295</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52150"&gt;@rajeshm&lt;/a&gt;&amp;nbsp;, we discussed this and answered your question in your thread last week at&amp;nbsp;&lt;A href="https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684647" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/684647&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DO NOT FORMAT MACRO VARIABLES&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 10:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685365#M24295</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-21T10:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: macro varible (date) in proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685376#M24296</link>
      <description>&lt;P&gt;I merged this back into the original thread dealing with the same question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer stays: do not format macro variables.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 11:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-date/m-p/685376#M24296</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-21T11:14:10Z</dc:date>
    </item>
  </channel>
</rss>

