<?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 Return particular dates for the past 16 years in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Return-particular-dates-for-the-past-16-years/m-p/697857#M213351</link>
    <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN style="font-family: inherit;"&gt;Hi,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN style="font-family: inherit;"&gt;i need to output only the particular dates from current to the past 16 years.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;I have one code, which lists all the quarters..i need to modify that in such a way it should return only the current quarter in each of the past hears.&lt;/P&gt;&lt;P&gt;Ex: If current quaretr = 2020Q2, it should return (2020Q2,2019Q2,2018Q2........) in a specific format int he ouput.&lt;/P&gt;&lt;P&gt;The code is as below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%let REPORTING_PERIOD_YYYYMMDD =20200630;
%let year_count   = 16;
%put &amp;amp;year_count;
%let val_date_current = %sysfunc(dhms(%sysfunc(inputn(&amp;amp;reporting_period_yyyymmdd., yymmdd8)),0, 0, 0));
%put &amp;amp;val_date_current;
%let val_date_first = %sysfunc(dhms(%sysfunc(intnx(year, %sysfunc(datepart(&amp;amp;val_date_current.)),-&amp;amp;year_count., end)), 0,0, 0));
%put &amp;amp;val_date_first;
%let val_date_count = %eval(%sysfunc(intck(dtquarter, &amp;amp;val_date_first., &amp;amp;val_date_current.)) + 1);
%put &amp;amp;val_date_count;

data Final;
do val_date_count=1 to &amp;amp;val_date_count.;
            val_date = intnx('quarter', datepart(&amp;amp;val_date_first.), val_date_count-1, 'end');
            arr_VAL_DATE = strip(put(val_date, ddmmyy10.));
            output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chithra&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 10 Nov 2020 11:39:28 GMT</pubDate>
    <dc:creator>chithra</dc:creator>
    <dc:date>2020-11-10T11:39:28Z</dc:date>
    <item>
      <title>Return particular dates for the past 16 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-particular-dates-for-the-past-16-years/m-p/697857#M213351</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN style="font-family: inherit;"&gt;Hi,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN style="font-family: inherit;"&gt;i need to output only the particular dates from current to the past 16 years.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;I have one code, which lists all the quarters..i need to modify that in such a way it should return only the current quarter in each of the past hears.&lt;/P&gt;&lt;P&gt;Ex: If current quaretr = 2020Q2, it should return (2020Q2,2019Q2,2018Q2........) in a specific format int he ouput.&lt;/P&gt;&lt;P&gt;The code is as below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%let REPORTING_PERIOD_YYYYMMDD =20200630;
%let year_count   = 16;
%put &amp;amp;year_count;
%let val_date_current = %sysfunc(dhms(%sysfunc(inputn(&amp;amp;reporting_period_yyyymmdd., yymmdd8)),0, 0, 0));
%put &amp;amp;val_date_current;
%let val_date_first = %sysfunc(dhms(%sysfunc(intnx(year, %sysfunc(datepart(&amp;amp;val_date_current.)),-&amp;amp;year_count., end)), 0,0, 0));
%put &amp;amp;val_date_first;
%let val_date_count = %eval(%sysfunc(intck(dtquarter, &amp;amp;val_date_first., &amp;amp;val_date_current.)) + 1);
%put &amp;amp;val_date_count;

data Final;
do val_date_count=1 to &amp;amp;val_date_count.;
            val_date = intnx('quarter', datepart(&amp;amp;val_date_first.), val_date_count-1, 'end');
            arr_VAL_DATE = strip(put(val_date, ddmmyy10.));
            output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chithra&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 10 Nov 2020 11:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-particular-dates-for-the-past-16-years/m-p/697857#M213351</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2020-11-10T11:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Return particular dates for the past 16 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-particular-dates-for-the-past-16-years/m-p/697870#M213362</link>
      <description>&lt;P&gt;You are working unnecessarily hard.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of important rules:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Macro variables should NOT be formatted (see &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;)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Macro variables should contain valid SAS dates (so, for example, January 1, 2020 is the integer 21915).&lt;/LI&gt;
&lt;LI&gt;Use formats to make dates appear as quarters, such as 2019Q2&lt;/LI&gt;
&lt;LI&gt;If you want to work with dates, then work with dates and don't make them date/time values by adding in hours,minutes,seconds&lt;/LI&gt;
&lt;LI&gt;If you want to work iterate over years, don't iterate over months&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my code to do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let REPORTING_PERIOD_YYYYMMDD = %sysfunc(inputn(20200630,yymmdd8.)); /* Macro variable is a valid SAS date, unformatted */
%put &amp;amp;=reporting_period_yyyymmdd;
%let year_count   = 16;

data Final;
    do year_count=1 to &amp;amp;year_count.;
            val_date = intnx('year',&amp;amp;reporting_period_yyyymmdd, -year_count, 's');
            output;
    end;
    format val_date yyq.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 14:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-particular-dates-for-the-past-16-years/m-p/697870#M213362</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-10T14:10:02Z</dc:date>
    </item>
  </channel>
</rss>

