@mlogan: 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.
If your data are in the form I saw in your most recent edits, I think that the following accomplishes the task as stated:
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()),&offset.,b)),0,s)))),3);
%let end=%substr(%sysfunc(year(%sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&offset.,e)),0,s)))),3);
data want_year&start._&end.;
set year&start._&end.;
if %sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&offset.,b)),0,s)) le
date1 le %sysfunc(intnx(year,%sysfunc(intnx(year.3,%sysfunc(today()),&offset.,e)),-0,s));
run;
%mend getrecs;
%getrecs(0) /*to get current year*/
%getrecs(-1) /*to get previous year*/
Art, CEO, AnalystFinder.com
... View more