****************************************************************************************************
*                                           PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: ms_createpov4.sas  
*
* Created (mm/dd/yyyy): 02/13/2017
* Last modified: 03/23/2017
* Version: 1.0
*
*--------------------------------------------------------------------------------------------------
* PURPOSE:
*	This program will create the exposure episodes for TYPE4 analysis 
*	(deliveries in pregnancy studies) 
*
*  Program inputs:                                                                                   
*	-Dataset with potential index dates (POV1)  
*   -Dataset with claims defined as being potential index dates
* 
*  Program outputs:                                                                                                                                       
* 	-Dataset with exposure episodes (POV4)
* 
* PARAMETERS:
*  	-CohortId = Identifier for the cohort being processed (primary, secondary)
*
*  Programming Notes:                                                                                
*                                                                           
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO: 
*  Mini-Sentinel Coordinating Center
*  info@mini-sentinel.org
*
*--------------------------------------------------------------------------------------------------
*  CHANGE LOG: 
*
*   Version   Date       Initials	   Comment (reference external documentation when available)
*   -------   --------   --------   ---------------------------------------------------------------
*             mm/dd/yy
*
***************************************************************************************************;

%macro ms_createpov4t4(CohortId=);

%put =====> MACRO CALLED: ms_createpov4t4 v1.0;

	%IF %STR("&CohortId.") = %STR("") %THEN %DO;		
		proc sort data=_pov1 (drop=ConcWashPer RXSUP RXAMT DaysUntreated episodegap episodegap2 episodegaptype2 expextper expextper2
		ittdays ittdays2 t4cohortdef t4CohortDef2 t4fupwashper2 WashPer2);
		by PatId EpisodeStartDt;
		run;

		proc sort data=_GroupEpis;
		by PatId EpisodeStartDt;
		run;

		data _POV4;
	    merge _POV1 (in=a)
			  _GroupEpis;
	    by PatId EpisodeStartDt;
		if a;	
		run;				
	%END; 	

%put NOTE: ********END OF MACRO: ms_createpov4t4 v1.0********;

%mend ms_createpov4t4;