 <pre><code>/**** get some dates to play with ****/ data dates(keep=i thisdate); offset = input('01Jan2015',DATE9.); do i=1 to 100; thisdate = offset + round(599*ranuni(1)+1); *** within 600 days from offset; output; end; format thisdate date9.; run; /**** BTW: intnx('month',thisdate,1)-1 = first day of next month. Deduct 1 to get the last day of the current month. intnx('month',thisdate,0,"BEGINNING") = first day of the current month ****/ proc sql; create table first5_last5 AS SELECT * FROM dates /* replace with name of your data set */ WHERE /* replace all occurences of 'thisdate' with name of your date variable */ ( intnx('month',thisdate,1)-5 &lt;= thisdate &lt;= intnx('month',thisdate,1)-1 ) OR ( intnx('month',thisdate,0,"BEGINNING") &lt;= thisdate &lt;= intnx('month',thisdate,0,"BEGINNING")+4 ) ORDER BY thisdate; quit; </code></pre>