LIBNAME my '/hsm1/army-other/username/folder’;
%macro patuniq (fy2,fm2); *extracts each monthly file and appends to my.cohort_patuniq;

filename invm3 pipe "uncompress -c /mdr/pub/deers/detail/vm6ben/fy&fy2./fm&fm2..txt.Z";

DATA vm6; *imports name and birthdt as well for later error checks;
infile invm3 lrecl=700 missover;
input
@9 SPONSSN $char9.
@21 DDS_CD $char2.
@24 BENSSN $char9.
@34 birthdt yymmdd8.
@201 last_name $char26.
@227 first_name $char20.
@495 PATUNIQ $char10.;

if patuniq ne "";
format birthdt yymmdd10.;
RUN;
PROC SQL;
CREATE TABLE patuniq&fy2.&fm2. AS
SELECT *
FROM cohort as a, vm6 as b
WHERE a.benssn=b.benssn
;
QUIT;

*adds each file to permanent file in library;
proc append data = patuniq&fy2.&fm2. base=my.cohort_patuniq force;
run;

%mend patuniq;

*cohort file with limited variable set for matching to MDR data;
data cohort (keep = benssn fmp_ssn dob lastname firstname);
set my.complete_cohort;
run;

*calls macro for fiscal year 2015 (October 2014-September 2015);
%dodid(fy2=15,fm2=02) /*November 2014*/
%dodid(fy2=15,fm2=01) /*October 2014*/