<?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: Dynamic month and year selection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668282#M200305</link>
    <description>&lt;P&gt;Thank you so much, It works for me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jul 2020 07:52:54 GMT</pubDate>
    <dc:creator>harshpatel</dc:creator>
    <dc:date>2020-07-10T07:52:54Z</dc:date>
    <item>
      <title>Dynamic month and year selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668266#M200295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to filter data based on month and year selection&lt;/P&gt;
&lt;P&gt;IF month is April and year is 2020 then data should filter as 2020 , 2019 and 2018&lt;/P&gt;
&lt;P&gt;But if month is not in April and year is 2020 then data should filter as 2020 and 2019 only two years&lt;/P&gt;
&lt;P&gt;I want this in SAS coding&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;For April it should come three years. This year, Previous Year and Previous to previous Year (3 years)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;For Other Months it should come two years. This year, Previous Year&amp;nbsp; (2 years)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly help on this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Harsh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 06:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668266#M200295</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-07-10T06:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic month and year selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668270#M200299</link>
      <description>&lt;P&gt;Here's some untested code for 1 of many possible solutions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    end_year=year(today());
    current_month=month(today());
    if current_month=4 then start_year=end_year - 2;
    else start_year = end_year - 1;
    call symputx('end_year', end_year);
    call symputx('start_year', start_year);
run;

%put &amp;amp;=start_year &amp;amp;=end_year;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit: My assumption was that you meant if current year was 2020.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 06:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668270#M200299</guid>
      <dc:creator>ketpt42</dc:creator>
      <dc:date>2020-07-10T06:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic month and year selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668274#M200301</link>
      <description>&lt;P&gt;The coding will depend on your data like if you've got SAS date or datetime values. Kindly post some sample data in the form of a tested SAS data step creating such data and then show us the desired outcome using this sample data.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 07:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668274#M200301</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-10T07:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic month and year selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668275#M200302</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Assuming your month and year selections are stored in macro variables:*/

%let month=4;
%let year=2020;

data _null_;
if &amp;amp;year eq 2020 then do;
if &amp;amp;month eq 4 then call symput('filter','(where=(2018 le year le 2020))');
else if &amp;amp;month ne 4 then call symput('filter','(where=(2019 le year le 2020))');
end;
run;

data have;
input Year Rate;
format Rate 8.2;
datalines;
2016 45.31
2017 44.72
2018 47.71
2019 49.26
2020 51.42
2021 52.65
;
run;

data want;
set have &amp;amp;filter.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jul 2020 07:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668275#M200302</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2020-07-10T07:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic month and year selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668282#M200305</link>
      <description>&lt;P&gt;Thank you so much, It works for me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 07:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-month-and-year-selection/m-p/668282#M200305</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-07-10T07:52:54Z</dc:date>
    </item>
  </channel>
</rss>

