<?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: Create a list of date of each end of month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332699#M74917</link>
    <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would make a macro "function" to build the desired list based on current date like this,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_of_dates(NOW,FORMAT);
%let _DAY=%eval(%sysfunc(intnx(year,&amp;amp;NOW,-1,e))+1);
%let _NOW=%eval(%sysfunc(intnx(month,&amp;amp;NOW,0,b))-1);
%if &amp;amp;_DAY gt &amp;amp;_NOW %then %let _DAY=%sysfunc(intnx(year,&amp;amp;NOW,-1,b));
%do _I=&amp;amp;_DAY %to &amp;amp;_NOW %by 31;
"%sysfunc(putn(%sysfunc(intnx(month,&amp;amp;_I,0,end)),&amp;amp;FORMAT))"
%end;
%mend list_of_dates; * build a IN list of dates;

data want;
set have;
    where periode in ( %list_of_dates(%sysfunc(today()),yymmdds10.) );
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;%sysfunc(today()) wil retrieve today's date&lt;/P&gt;
&lt;P&gt;yymmdds10. is the date format for YYYY/MM/DD (you can change it any know SAS format)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2017 16:39:50 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2017-02-14T16:39:50Z</dc:date>
    <item>
      <title>Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332652#M74895</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I would like to create a sas macro who will give us a list containing all end of month according to the current date.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;For example:&lt;/U&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If the macro is launch in March, we will have&amp;nbsp;&lt;SPAN&gt;list_of_date=('31/01/2017', '28/02'2017').&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;If &lt;SPAN&gt;the macro is launch&lt;/SPAN&gt;&amp;nbsp;in June, we will have&amp;nbsp;&lt;SPAN&gt;list_of_date=('31/01/2017', '28/02'2017', '31/03/2017','30/04/2017', '31/05/2017')&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;If&amp;nbsp;the macro is launch in junuary (of year N+1), we will have the end of all month of the previous year.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for all.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 15:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332652#M74895</guid>
      <dc:creator>foxrol94</dc:creator>
      <dc:date>2017-02-14T15:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332656#M74897</link>
      <description>&lt;P&gt;What do you intend to do with the list? I ask because for a lot of uses your date format would not be very useful.&lt;/P&gt;
&lt;P&gt;And I do believe some of your dates in the June example have the wrong month.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 15:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332656#M74897</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-14T15:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332670#M74902</link>
      <description>Hi, &lt;BR /&gt;sorry it was a mistake.&lt;BR /&gt;The list is for filtering a column who have values like('31/01/2017', '28/02'2017', '31/03/2017','30/04/2017', '31/05/2017').</description>
      <pubDate>Tue, 14 Feb 2017 15:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332670#M74902</guid>
      <dc:creator>foxrol94</dc:creator>
      <dc:date>2017-02-14T15:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332672#M74903</link>
      <description>&lt;P&gt;Here is the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let list_of_date=periode in ('31/01/2017') ; 

data his_cum;
set REF_TREF.HIS_opn_stats;
   where &amp;amp;list_of_date.;
run;

&lt;/PRE&gt;
&lt;P&gt;Each month i manually add the end of the month to the &lt;STRONG&gt;list_of_date&lt;/STRONG&gt; macro_variable.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 15:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332672#M74903</guid>
      <dc:creator>foxrol94</dc:creator>
      <dc:date>2017-02-14T15:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332683#M74907</link>
      <description>&lt;P&gt;The following could probably be simplified, but does what you want (I think):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro getdates();
  data _null_;
    length want $255;
    end=intnx('month',today(),-1,'E');
    want='';
    do i=1 to month(end);
      date=catt("'",put(intnx('month',mdy(i,1,year(end)),0,'E'),yymmdds10.),"'");
      want=catx(',',want,date);
    end;
    want=catt('periode in (',want,')');
    call symput('list_of_date',want);
  run;
%mend getdates;

%getdates
%put &amp;amp;list_of_date.;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 16:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332683#M74907</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-14T16:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332699#M74917</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would make a macro "function" to build the desired list based on current date like this,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_of_dates(NOW,FORMAT);
%let _DAY=%eval(%sysfunc(intnx(year,&amp;amp;NOW,-1,e))+1);
%let _NOW=%eval(%sysfunc(intnx(month,&amp;amp;NOW,0,b))-1);
%if &amp;amp;_DAY gt &amp;amp;_NOW %then %let _DAY=%sysfunc(intnx(year,&amp;amp;NOW,-1,b));
%do _I=&amp;amp;_DAY %to &amp;amp;_NOW %by 31;
"%sysfunc(putn(%sysfunc(intnx(month,&amp;amp;_I,0,end)),&amp;amp;FORMAT))"
%end;
%mend list_of_dates; * build a IN list of dates;

data want;
set have;
    where periode in ( %list_of_dates(%sysfunc(today()),yymmdds10.) );
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;%sysfunc(today()) wil retrieve today's date&lt;/P&gt;
&lt;P&gt;yymmdds10. is the date format for YYYY/MM/DD (you can change it any know SAS format)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 16:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332699#M74917</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-14T16:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332738#M74931</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5599"&gt;@foxrol94&lt;/a&gt; wrote:&lt;BR /&gt;Hi, &lt;BR /&gt;sorry it was a mistake.&lt;BR /&gt;The list is for filtering a column who have values like('31/01/2017', '28/02'2017', '31/03/2017','30/04/2017', '31/05/2017').&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't mention HOW you actually use the list, to keep or drop.&lt;/P&gt;
&lt;P&gt;Note that this line of code in a data step or proc sql&amp;nbsp;will only keep records that the character date variable is for the last day of the month&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;where&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; input(datevar,&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'month'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,input(datevar,&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;),&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;0&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'E'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;This would exclude&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;where&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; input(datevar,&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) ne intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'month'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,input(datevar,&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;),&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;0&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'E'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 17:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332738#M74931</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-14T17:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332756#M74936</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5599"&gt;@foxrol94&lt;/a&gt; wrote:&lt;BR /&gt;Hi, &lt;BR /&gt;sorry it was a mistake.&lt;BR /&gt;The list is for filtering a column who have values like('31/01/2017', '28/02'2017', '31/03/2017','30/04/2017', '31/05/2017').&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your list suggests that you have dates stored as strings of length 10, with a DMY sequence. This is sub-optimal for several reasons: you can't use any SAS date functions directly, and the sort sequence will not be chronological. And you need to create your list for the "in" condition with quotes, which unnecessarily complicates things. With SAS dates, you can create a simple list of numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332756#M74936</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-14T18:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332884#M74968</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
 do i=1 to month(today());
  date=intnx('month',mdy(i,1,year(today())),0,'e');
  output;
 end;
 format date date9.;
run;
proc sql noprint;
select quote(put(date,date9.)) into : list_of_date separated by ','
 from x;
quit;


%let list_of_date=(&amp;amp;list_of_date);

%put &amp;amp;list_of_date ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Feb 2017 03:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/332884#M74968</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-15T03:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create a list of date of each end of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/428616#M105837</link>
      <description>&lt;P&gt;/*USING MACRO*/&lt;BR /&gt;%MACRO MONTHS;&lt;BR /&gt;%DO M=1 %TO 40;&lt;BR /&gt;DATA dateR;&lt;BR /&gt;FORMAT SEE DATE9.;&lt;BR /&gt;SEE = INTNX('MONTH',TODAY(),-&amp;amp;M,'B');&lt;BR /&gt;RUN;&lt;BR /&gt;&amp;nbsp;PROC APPEND&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;DATA=dateR&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;BASE=want_data&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;FORCE;&lt;BR /&gt;%END;&lt;BR /&gt;%MEND MONTHS;&lt;BR /&gt;%MONTHS&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 21:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-list-of-date-of-each-end-of-month/m-p/428616#M105837</guid>
      <dc:creator>NiyiAwe1</dc:creator>
      <dc:date>2018-01-17T21:11:16Z</dc:date>
    </item>
  </channel>
</rss>

