<?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: First and last day of month using Macros in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164863#M31864</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;INTNX wants a SAS Date, and 201405 is not a SAS date (at least it's not the SAS date you want).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use INPUT() to convert 201405 to a SAS date, something like: (untested)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%put %sysfunc(inputn(201405,yymmn6.),mmddyy10.); 
%put %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,B),mmddyy10.);
%put %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,E),mmddyy10.);

Where
&amp;nbsp; report _date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ge %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,B))
&amp;nbsp; and report_date le %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,E))
;
&lt;P&gt;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;Actually you probably dont need the %sysfunc, and could instead just replace &amp;amp;month_key in your approach with inputn(&amp;amp;monthkey,yymmn6.)&amp;nbsp; .&amp;nbsp; But sometimes the macro language cam makes it easier to test/debug (not sure I've ever said *that* before...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;-Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 May 2014 18:14:45 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2014-05-19T18:14:45Z</dc:date>
    <item>
      <title>First and last day of month using Macros in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164861#M31862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My requirement is to use a filter code to select only current month's data from given table and condition I need to select is where report _date &amp;gt;= first_day_of_month and report_date &amp;lt;= last_day_of_month&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My data looks like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Account_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Report_date&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12JUN2013&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17JAN2014&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19MAY2014&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code that I need to modify (I wrote this )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let month_key=201405;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;Create table work.want as&lt;/P&gt;&lt;P&gt;Select * from Work.have&lt;/P&gt;&lt;P&gt;Where report _date &amp;gt;= intnx ('month', &amp;amp;month_key,0) and report_date&amp;lt;=intnx('month',&amp;amp;month_key,0)-1;&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value of month_key will be passed like this only. Don't know where I am going wrong but it's producing wrong output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Need your help on this.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Thanks in advance. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 17:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164861#M31862</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2014-05-19T17:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: First and last day of month using Macros in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164862#M31863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; &lt;BR /&gt;data have;&lt;BR /&gt;input Account_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Report_date : date9.;&lt;BR /&gt;format report_date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12JUN2013&lt;BR /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17JAN2014&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19MAY2014&lt;BR /&gt;;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%let month_key=201405;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;BR /&gt;Create table work.want as&lt;BR /&gt;Select * from Work.have&lt;BR /&gt;Where year(report_date)=%substr(&amp;amp;month_key,1,4) and month(report_date)=%substr(&amp;amp;month_key,5);&lt;BR /&gt;Quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 18:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164862#M31863</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2014-05-19T18:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: First and last day of month using Macros in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164863#M31864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;INTNX wants a SAS Date, and 201405 is not a SAS date (at least it's not the SAS date you want).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use INPUT() to convert 201405 to a SAS date, something like: (untested)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%put %sysfunc(inputn(201405,yymmn6.),mmddyy10.); 
%put %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,B),mmddyy10.);
%put %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,E),mmddyy10.);

Where
&amp;nbsp; report _date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ge %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,B))
&amp;nbsp; and report_date le %sysfunc(intnx (month,%sysfunc(inputn(201405,yymmn6.)) ,0,E))
;
&lt;P&gt;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;Actually you probably dont need the %sysfunc, and could instead just replace &amp;amp;month_key in your approach with inputn(&amp;amp;monthkey,yymmn6.)&amp;nbsp; .&amp;nbsp; But sometimes the macro language cam makes it easier to test/debug (not sure I've ever said *that* before...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;-Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 18:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164863#M31864</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2014-05-19T18:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: First and last day of month using Macros in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164864#M31865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;tested:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;Create table work.want as&lt;/P&gt;&lt;P&gt;Select * from Work.have&lt;/P&gt;&lt;P&gt;Where report_date between intnx('month',%sysfunc(inputn(&amp;amp;month_key,yymmn6.)),0,'b') and intnx('month',%sysfunc(inputn(&amp;amp;month_key,yymmn6.)),0,'e');&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;Create table work.want2 as&lt;/P&gt;&lt;P&gt;Select * from Work.have&lt;/P&gt;&lt;P&gt;Where report_date between intnx('month',input("&amp;amp;month_key",yymmn6.),0,'b') and intnx('month',input("&amp;amp;month_key",yymmn6.),0,'e');&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 19:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-day-of-month-using-Macros-in-proc-sql/m-p/164864#M31865</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2014-05-19T19:04:42Z</dc:date>
    </item>
  </channel>
</rss>

