**************************************************************************************************** * PROGRAM OVERVIEW **************************************************************************************************** * * PROGRAM: ms_envelope.sas * * Created (mm/dd/yyyy): 07/31/2014 * Last modified: 11/14/2016 * Version: 2.1 * *-------------------------------------------------------------------------------------------------- * PURPOSE: * This program uses data from the MSDD to recode non-inpatient encounters to inpatient if they were * determined to have occurred during an inpatient stay. Please note that this operation is done * without using the ENCOUNTERID variable, as this variable can be inconsistent across data * partner datasets. * * Program inputs: * -SAS data file with diagnosis/procedure claims data * -SAS data file with encounter data * * Program outputs: * -SAS data file (.SAS7BDAT format) with reclassified claims * * PARAMETERS: * -INFILE = Name of SAS dataset with diagnosis and/or procedure claims data * -ENCOUNTERINFILE = Name of SAS dataset with encounter data * -OUTFILE = Name of output file with reclassified claims * * Programming Notes: * * * *-------------------------------------------------------------------------------------------------- * CONTACT INFO: * Mini-Sentinel Coordinating Center * info@mini-sentinel.org * *-------------------------------------------------------------------------------------------------- * CHANGE LOG: * * Version Date Initials Comment (reference external documentation when available) * ------- -------- -------- --------------------------------------------------------------- * 2.1 11/14/2014 AP Added ability to turn off envelope macro * ***************************************************************************************************; %macro MS_ENVELOPE(INFILE=,ENCOUNTERINFILE=,OUTFILE=); %put =====> MACRO CALLED: ms_envelope v2.1; *Reclassification as inpatient all selected claims within admission and discharge dates of an inpatient stay; *Get Unique ADate-Ddate combinations; proc sort nodupkey data=&ENCOUNTERINFILE.(keep=PatId Adate Ddate EncType where=(EncType='IP')) out=_IPdates(keep=PatId Adate Ddate); by PatId Adate Ddate; run; *Assing claim number for unique record merging; data &OUTFILE.; set &INFILE.; Clm = _N_; rename EncType=EncTypeOrig; run; %let sign = %str(<=); %if &run_envelope. = 1 %then %let sign = %str(<); proc sql noprint; create table _datematch as Select claimtb.Clm From &OUTFILE.(where=(EncTypeOrig not in('IP'))) as claimtb, _IPDates as datetb Where claimtb.PatId = datetb.PatId and datetb.ADate &sign. claimtb.ADate <= max(datetb.ADate,datetb.DDate); quit; proc sort nodupkey data = _datematch(keep=Clm); by Clm; run; *For each record in INFILE matching an inpatient day date, recode encounter type as inpatient; data &OUTFILE.(drop=EncTypeOrig Clm); merge &OUTFILE.(in=a) _datematch(in=b); by Clm; EncType=EncTypeOrig; if b then do; if EncTypeOrig not in('IP') then pdx='X'; EncType='IP'; end; run; proc datasets library = work nolist nowarn nodetails; delete _IPDates; quit; %put NOTE: ******** END OF MACRO: ms_envelope v2.1 ********; %mend MS_ENVELOPE;