<?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: Coding with Fiscal Year in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462985#M7031</link>
    <description>&lt;P&gt;As long as you get YEAR variable .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Year18_19;
INPUT Date1 Course_ID $4. age 3.;
INFORMAT Date1 Date9.;
FORMAT Date1 Date9.;
fiscal_year=year(intnx('year.3',date1,0));
DATALINES;
05Jan2018 ENG1 10
16Feb2018 Bio2 15
09Apr2018 Che1 10
15Jan2018 Bio1 11
11MAY2018 Eng2 15
09Mar2018 Phy2 11
20Feb2018 Che1 15
;
RUN;

data want;
 set Year18_19;
 if fiscal_year=2018;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 17 May 2018 12:38:23 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-05-17T12:38:23Z</dc:date>
    <item>
      <title>Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462681#M7025</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA Year18_19;
INPUT Date1 Course_ID $4. age 3.;
INFORMAT Date1 Date9.;
FORMAT Date1 Date9.;
DATALINES;
05Jan2018 ENG1 10
16Feb2018 Bio2 15
09Apr2018 Che1 10
15Jan2018 Bio1 11
11MAY2018 Eng2 15
09Mar2018 Phy2 11
20Feb2018 Che1 15
;
RUN;

PROC PRINT DATA=Year18_19 NOOBS;
RUN;

DATA Year17_18;
INPUT Date1 Course_ID $4. age 3.;
INFORMAT Date1 Date9.;
FORMAT Date1 Date9.;
DATALINES;
05Jan2018 ENG1 10
16Jan2017 Bio2 15
09Feb2017 Che1 10
15Mar2018 Bio1 11
11MAY2017 Eng2 15
22Apr2017 Phy2 11
20Feb2018 Che1 15
;
RUN;

PROC PRINT DATA=Year17_18 NOOBS;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi,&lt;BR /&gt;My Fiscal Year goes from March 01 to February 30. When I am in the month of May now, I want to pull all the data for this fiscal year (from dataset Year18_19 above) UNTIL last month.&lt;BR /&gt;and I want the system to calculate that from sysdate.&lt;/P&gt;
&lt;P&gt;So for this fiscal year code should return the following observations from dataset Year18_19:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Date1 Course_ID age&lt;/STRONG&gt;&lt;BR /&gt;09Apr2018 Che1 10&lt;BR /&gt;11MAY2018 Eng2 15&lt;BR /&gt;09Mar2018 Phy2 11&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Now I want to do the same for the last Fiscal year (Year17_18) which will return:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Date1 Course_ID age&lt;/STRONG&gt;&lt;BR /&gt;05Jan2018 ENG1 10&lt;BR /&gt;11MAY2017 Eng2 15&lt;BR /&gt;22Apr2017 Phy2 11&lt;BR /&gt;20Feb2018 Che1 15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 13:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462681#M7025</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2018-05-16T13:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462690#M7026</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Year18_19;
INPUT Date1 Course_ID $4. age 3.;
INFORMAT Date1 Date9.;
FORMAT Date1 Date9.;
fiscal_year=year(intnx('year.3',date1,0));
DATALINES;
05Jan2018 ENG1 10
16Feb2018 Bio2 15
09Apr2018 Che1 10
15Jan2018 Bio1 11
11MAY2018 Eng2 15
09Mar2018 Phy2 11
20Feb2018 Che1 15
;
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 May 2018 13:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462690#M7026</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-16T13:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462714#M7027</link>
      <description>Thanks Kharp. I wanted to query from the Year18_19 and Year17_18 dataset and get the following output:&lt;BR /&gt;&lt;BR /&gt;From Year18_19:&lt;BR /&gt;----------------------&lt;BR /&gt;&lt;BR /&gt;Date1 Course_ID age&lt;BR /&gt;09Apr2018 Che1 10&lt;BR /&gt;11MAY2018 Eng2 15&lt;BR /&gt;09Mar2018 Phy2 11&lt;BR /&gt;&lt;BR /&gt;From Year17_18:&lt;BR /&gt;----------------------&lt;BR /&gt;&lt;BR /&gt;Date1 Course_ID age&lt;BR /&gt;05Jan2018 ENG1 10&lt;BR /&gt;11MAY2017 Eng2 15&lt;BR /&gt;22Apr2017 Phy2 11&lt;BR /&gt;20Feb2018 Che1 15&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 16 May 2018 14:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462714#M7027</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2018-05-16T14:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462985#M7031</link>
      <description>&lt;P&gt;As long as you get YEAR variable .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Year18_19;
INPUT Date1 Course_ID $4. age 3.;
INFORMAT Date1 Date9.;
FORMAT Date1 Date9.;
fiscal_year=year(intnx('year.3',date1,0));
DATALINES;
05Jan2018 ENG1 10
16Feb2018 Bio2 15
09Apr2018 Che1 10
15Jan2018 Bio1 11
11MAY2018 Eng2 15
09Mar2018 Phy2 11
20Feb2018 Che1 15
;
RUN;

data want;
 set Year18_19;
 if fiscal_year=2018;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 May 2018 12:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/462985#M7031</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-17T12:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463418#M7040</link>
      <description>I Ksharp, I actually wanted to make it dynamic so that at any given month when I will run my code, it will grab/filter the data until the last date of previous month of every year of the date field.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;INPUT Date Course_ID $4.;&lt;BR /&gt;INFORMAT Date Date9.;&lt;BR /&gt;FORMAT Date Date9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;05Jan2018 ENG1&lt;BR /&gt;16Jan2017 Bio2&lt;BR /&gt;09Dec2016 Che1&lt;BR /&gt;15Jan2018 Bio1&lt;BR /&gt;11MAY2015 Eng2&lt;BR /&gt;12Mar2016 Phy2&lt;BR /&gt;20May2018 Che1&lt;BR /&gt;;&lt;BR /&gt;PROC PRINT NOOBS;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;I have written the following code, but can really make it work at the end. Can you please help. Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA want;&lt;BR /&gt;SET have;&lt;BR /&gt;Y0_FYb=YEAR(intnx('YEAR.4',date,0));&lt;BR /&gt;Y0_FYe=YEAR(intnx('YEAR.4',date,0,'e'));&lt;BR /&gt;&lt;BR /&gt;Y0_fromdate=intnx('year.4',date,0,'b');&lt;BR /&gt;Y0_todate=intnx('MONTH',date,-1,'e');&lt;BR /&gt;&lt;BR /&gt;Y1P_FY=YEAR(intnx('YEAR.4',date,0));&lt;BR /&gt;Y1P_fromdate=intnx('year.4',date,0,'b');&lt;BR /&gt;Y1P_todate=intnx('MONTH',date,-1,'e');&lt;BR /&gt;&lt;BR /&gt;Rep_ToMonth=intnx('MONTH', date , -1, 'e');&lt;BR /&gt;fy2 = COMPRESS(Y0_FYb||"-"||Y0_FYe);&lt;BR /&gt;FORMAT 	Y0_fromdate&lt;BR /&gt;		Y0_todate Rep_ToMonth date date9.;&lt;BR /&gt;PROC PRINT NOOBS;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA Final;&lt;BR /&gt; SET want;&lt;BR /&gt; WHERE Rep_ToMOnth &amp;gt;= intnx('MONTH', %SYSFUNC(today()), -1, 'e');&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT NOOBS;&lt;BR /&gt;RUN;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 May 2018 19:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463418#M7040</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2018-05-18T19:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463506#M7042</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;I actually wanted to make it dynamic so that at any given month&amp;nbsp;"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;according to what ? and How ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 12:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463506#M7042</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-19T12:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463546#M7043</link>
      <description>&lt;P&gt;Hi Ksharp, &lt;BR /&gt;Sorry my post did not make much sense I just realized. Here is what my data situation and what I want. Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;My fiscal year goes from March 1 to end of February. At any given day (let's say today) I have my current fiscal year data until today (Mar 01 2018 - May 19 2018) and data from last 2 full fiscal year. &lt;BR /&gt;&lt;BR /&gt;For example today I have:&lt;BR /&gt;FiscalYear 2018-2019: Mar 01 2018 - May 19 2019&lt;BR /&gt;Fiscal Year 2017-2018: Mar 01 2017 - Feb 28 2018&lt;BR /&gt;Fiscal Year 2016-2017: Mar 01 2016 - Feb 28 2017&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;WHAT I WANT:&lt;BR /&gt;-------------------&lt;BR /&gt;&lt;BR /&gt;Filter the data until the end of last month (in my case April of 2018-2019 Fiscal Year) and I want the code to determine that from system date.&lt;BR /&gt;Filter the data from each last 2 fiscal year until the end of April of each year. In my example it will be April 2017 &amp;amp; April 2016.&lt;BR /&gt;Every month when I will run my code, I don't want to change my Year/Fiscal year manually on my code.&lt;BR /&gt;&lt;BR /&gt;My output table should look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;16Mar2016 Bio2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;01Mar2018 Eng1&lt;BR /&gt;15Mar2018 Bio1&lt;BR /&gt;27Apr2018 Bio1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HERE IS MY Example DATA&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;INPUT Date Course_ID $4.;&lt;BR /&gt;INFORMAT Date Date9.;&lt;BR /&gt;FORMAT Date Date9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;05Jan2018 ENG1&lt;BR /&gt;16Aug2017 Bio2&lt;BR /&gt;11MAY2015 Eng2&lt;BR /&gt;28Feb2018 Geo2&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;16Mar2016 Bio2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;01Mar2018 Eng1&lt;BR /&gt;09Feb2017 Che1&lt;BR /&gt;19Jan2015 Phy2&lt;BR /&gt;15Mar2018 Bio1&lt;BR /&gt;12Mar2015 Phy2&lt;BR /&gt;19May2018 Che1&lt;BR /&gt;27Apr2018 Bio1&lt;BR /&gt;;&lt;BR /&gt;PROC PRINT NOOBS;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 19:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463546#M7043</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2018-05-19T19:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463550#M7044</link>
      <description>&lt;P&gt;Does the following do what you want?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
  INPUT Date Course_ID $4.;
  INFORMAT Date Date9.;
  FORMAT Date Date9.;
  DATALINES;
05Jan2018 ENG1
16Jan2017 Bio2
11MAY2015 Eng2
28Feb2018 Geo2
01Mar2018 Eng1
09Feb2017 Che1
19Jan2015 Phy2
15Mar2018 Bio1
12Mar2015 Phy2
19May2018 Che1
;

data want;
  set have;
  if date ge intnx('year',intnx('year.3',today(),0,'b'),-2,'s');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 17:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463550#M7044</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-19T17:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463629#M7045</link>
      <description>&lt;P&gt;Sorry. It is still confused to me .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data key;
start=intnx('month',today(),-1,'b');
end=intnx('month',today(),-1,'e');
output;

start=mdy(3,1,year(today()));
end=mdy(3,31,year(today()));
output;

start=mdy(3,1,year(today())-1);
end=mdy(3,31,year(today())-1);
output;

start=mdy(3,1,year(today())-2);
end=mdy(3,31,year(today())-2);
output;
format start end date9.;
run;


DATA have;
INPUT Date Course_ID $4.;
INFORMAT Date Date9.;
FORMAT Date Date9.;
DATALINES;
05Jan2018 ENG1
16Aug2017 Bio2
11MAY2015 Eng2
28Feb2018 Geo2
16Mar2016 Bio2
01Mar2018 Eng1
09Feb2017 Che1
19Jan2015 Phy2
15Mar2018 Bio1
12Mar2015 Phy2
19May2018 Che1
27Apr2018 Bio1
;

proc sql;
select a.*
 from have as a,key as b
  where date between start and end;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 May 2018 11:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463629#M7045</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-20T11:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463652#M7046</link>
      <description>Thanks Ksharp for your kind help.</description>
      <pubDate>Sun, 20 May 2018 19:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463652#M7046</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2018-05-20T19:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Coding with Fiscal Year</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463783#M7048</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan&lt;/a&gt;: You've marked this question as 'solved' but, as the posts have been edited and contain different have and want files than they originally contained, I'm not sure if you actually ever got a solution that accomplishes whatever it is that you're trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data are in the form I saw in your most recent edits, I think that the following accomplishes the task as stated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Year18_19;
  input Date1 Course_ID $4. age 3.;
  informat Date1 Date9.;
  format Date1 Date9.;
  datalines;
05Jan2018 ENG1 10
16Feb2018 Bio2 15
09Apr2018 Che1 10
15Jan2018 Bio1 11
11MAY2018 Eng2 15
09Mar2018 Phy2 11
20Feb2018 Che1 15
;
run;

data Year17_18;
  input Date1 Course_ID $4. age 3.;
  informat Date1 Date9.;
  format Date1 Date9.;
  datalines;
05Jan2018 ENG1 10
16Jan2017 Bio2 15
09Feb2017 Che1 10
15Mar2018 Bio1 11
11MAY2017 Eng2 15
22Apr2017 Phy2 11
20Feb2018 Che1 15
;
RUN;

%macro getrecs(offset);
  %let start=%substr(%sysfunc(year(%sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&amp;amp;offset.,b)),0,s)))),3);
  %let end=%substr(%sysfunc(year(%sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&amp;amp;offset.,e)),0,s)))),3);

  data want_year&amp;amp;start._&amp;amp;end.;
    set year&amp;amp;start._&amp;amp;end.;
    if %sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&amp;amp;offset.,b)),0,s)) le
    date1 le %sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&amp;amp;offset.,e)),-0,s));
  run;
%mend getrecs;

%getrecs(0) /*to get current year*/

%getrecs(-1) /*to get previous year*/
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 14:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Coding-with-Fiscal-Year/m-p/463783#M7048</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-21T14:19:30Z</dc:date>
    </item>
  </channel>
</rss>

