*establishes library named “my” directed at your assigned folder on the server;
LIBNAME my '/hsm1/army-other/username/folder’;

*macro selects each monthly beneficiary file and appends to my.cohort_patuniq.  This particular macro is searching for individual “patuniq” records which line up with the army medical record number or edipn.*

%macro patuniq (fy2,fm2); *macro searches by army fiscal year (October – September) and month;

*location of vm6 file labeled by fiscal year and fiscal month with appropriate code for macro;
filename invm6 pipe "uncompress -c /mdr/pub/deers/detail/vm6ben/fy&fy2./fm&fm2..txt.Z";

*from master record, creates smaller file with fewer variables (takes less processing memory and time) for individual patuniq (or edipn) records.  Also imports name and birthdate for later error checks to confirm records are an appropriate match;
DATA vm6;
infile invm6 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;

*matches file from master vm6 to the original study cohort file by beneficiary social security number.  Can use other patient identifier(s) as appropriate.
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;

*code below calls macro for fiscal year 2015 (October 2014-September 2015) for the first and second month of the fiscal year.;
%patuniq(fy2=15,fm2=02) /*November 2014*/
%patuniq(fy2=15,fm2=01) /*October 2014*/