/****************************************************************************** Project: Immigration Data Linkage Project (ircc_link) File: S:\ircc_link\prog\gillesd\concept_samples\return_migration.sas Programmer: Gilles R. Detillieux First Created: Sep. 8, 2022 Revisions: - Dec. 20, 2022: - adapted to updated "v2" datasets & split crosswalks - Dec. 22, 2022: - updated end dates to cover new data - Jan. 12, 2023: - adapted to most recent "v2" variable names - Mar. 5, 2025: - adapted to 2024 "V2" dataset & variable names, acqdt values - Jul. 22, 2025: - use get_ircc_pr macro to fetch data Input datasets: registry.ircc_crosswalk_1985jan_v2: IRCC linkage dataset, 1985-2023 registry.ircc_legacy_landing_1985jan_v2: IRCC landing data from 1985 to 1999 registry.ircc_landing_2000jan_v2: IRCC landing data from 2000 to 2023 registry.mhmrs_1970jun: MH insurance registry Description: This program finds landing date of immigrants living in Manitoba, for anyone listed in the IRCC immigration landing datasets and crosswalk, then gets their MB health insurance registry coverage episodes ending after landing, to calculate rates of return migration to Manitoba. ******************************************************************************/ options nocenter; *** Get a linked immigrant cohort from IRCC crosswalk and landing tables,; *** keep one record per valid PHIN.; %get_ircc_pr(cohort=, out=landing, dup=first); *** coverage episodes pulled from registry using regcov macro; *** ignore coverage gaps of 360 days or less; %regcov(dsname=landing, startdt=01jan1985, enddt=30nov2022, id=scrphin, outds=regcov, gapdays=360); *** sort by person so we can merge with grouped landing data; proc sort data=regcov; by scrphin covdt enddt; run; *** merge in landing data to find coverage episodes during or after landing; data landing; merge landing (in=in_la) regcov (in=in_co); by scrphin; if in_la and in_co and . < covdt <= '31dec2021'd and enddt >= landing_dt and landing_dt <= '31dec2021'd; run; *** get covcode variable from registry to match our coverage episodes; *** keep only covcode values we need to resolve returns after 'cannot locate'; proc sort data=registry.mhmrs_1970jun (keep=scrphin covdt acqdt rectype covcode) out=regcov; where acqdt <= '30nov2022'd and rectype in ('2','R') and '01jan1985'd <= covdt <= '31dec2021'd and ('2' <= covcode <= '9' or 'A' <= covcode <= 'G'); by scrphin covdt acqdt; run; * keep most recent acqdt; data regcov; set regcov; by scrphin covdt acqdt; if last.covdt; run; *** merge covcodes into landing data with matching coverage episode data; data landing; merge landing (in=in_la) regcov (in=in_co keep=scrphin covdt covcode); by scrphin covdt; if in_la; run; *** keep one record per person, categorizing reason for leaving & returning; data landing; set landing; by scrphin covdt enddt; retain covcnt rcovcode firstcanccode dropphin; if first.scrphin then do; covcnt = 0; rcovcode = ' '; firstcanccode = canccode; dropphin = 0; end; *** count coverage episodes and keep return date from 2nd after landing; covcnt = covcnt + 1; if covcnt = 2 then rcovcode = covcode; *** drop dupl. or registered in error (may show up under another phin); if canccode in ('W','5','6') then dropphin = 1; if last.scrphin and ^dropphin; canccode = firstcanccode; pop = 1; *** categorize outmigration; * Note: canccode A, C-R = Left Manitoba to some other known destination; length outmigration $18; if canccode = '0' then outmigration = 'Remained'; else if canccode = 'V' then outmigration = 'Remained'; else if canccode = '2' then outmigration = 'Remained'; * or 'Deceased'; else if canccode = '7' then outmigration = 'Cannot Locate'; else if canccode = 'A' or 'C' <= canccode <= 'R' then outmigration = 'Moved'; else outmigration = 'Other'; leftmb = (outmigration in ('Moved','Cannot Locate')); *** categorize return migration; * Note: covcode 2-9, A-G = New Resident from some other known location; * These count as return migration after cancellation due to 'cannot locate'; returned = (covcnt >= 2); remigration = 0; if returned and canccode = '7' and ('2' <= rcovcode <= '9' or 'A' <= rcovcode <= 'G') or returned and (canccode = 'A' or 'C' <= canccode <= 'R') then remigration = 1; lyear = year(landing_dt); label lyear = 'Landing Year'; label outmigration = 'Outmigration by Reason for Coverage Cancellation'; label leftmb = 'Status of outmigration (Moved or Cannot Locate)'; label remigration = 'Return Migration'; label returned = 'Person had 2+ coverage episodes'; run; *** summarize out/remigration counts by landing year and reason; proc tabulate data=landing; where leftmb; class lyear outmigration / order=formatted; var leftmb remigration; table lyear, leftmb='Outmigration'*outmigration=''*sum='N'*f=6.0 remigration*outmigration=''*(sum='N'*f=6.0 pctsum='%') / nocellmerge; title 'Return Migration Tates for Immigrants to Manitoba, by landing year and reason'; run; *** a little cleanup; proc delete data=landing regcov; run;