/*----------------------------------------------------------------------- © Copyright 2011-2013 University of Manitoba This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ----------------------------------------------------------------------------- Programmer: Say Hong Based on the previous work by Mahmoud Azimaee Please direct questions and comments to info@cpe.umanitoba.ca Version 2.0 Date: Feb. 22, 2013 This macro produce a percentage of linkable records over year for a specific dataset or a list of datasets. Macro Parameters: Domain = Libname of the dataset Db = Dataset prefix or Space separated list of dataset name Startyr = Beginning year Endyr = Ending year Bydate = Date variable (must be sas date) Phin = Name of phin variable (default value is scrphin) Type = Name of phintype (default value is scrphintype) Ytype = Default value is F, if set to C then linkability will be run by calendar year, otherwise linkablity will be performed by fiscal year (valid value is F/C) -----------------------------------------------------------------------*/ %macro dq_linkyr(domain=, db=, startyr=, endyr=, bydate=, phin=scrphin, type=scrphintype, ytype=F); %put; %put NOTE: Linkability over year macro (Version 2.0); %put NOTE: Say Hong; %put NOTE: Based on the previous work by Mahmoud Azimaee; %put; proc datasets nolist memtype=data; delete linkability_over_year; quit; proc format; value fy %do i = &startyr %to &endyr; %if %upcase(&ytype) = F %then "01apr&i"d - "31mar%eval(&i+1)"d = "&i/%eval(&i+1)"; %else %if %upcase(&ytype) = C %then "01jan&i"d - "31dec&i"d = "&i"; %end; Other = 'Other Years' ; value $phintype '0'='0 MH verified against concurrent registries' '1'='1 MH redirected to this ScrPHIN from FILEPHIN' '2'='2 MCHP modified sibling''s ScrPHIN' '3'='3 MCHP assigned ScrPHIN from Registry' '4'='4 MCHP db specific ScrPHIN - No MH found' '5'='5 MCHP db specific ScrPHIN - personid not incl in crosswalk' '6'='6 Not Defined June 2010' '7'='7 HCN is not Manitoba Resident' '8'='8 Missing or unspecified' '9'='9 System, not individual ScrPHIN' ; run; %if %sysfunc(countw(&db)) = 1 %then %do; proc sql noprint; select memname into :dsn_lst separated by ' ' from dictionary.members where libname = "%upcase(&domain)" and substr(memname, 1, %length(&db))="%upcase(&db)"; quit; %end; %else %let dsn_lst = &db; %let n_dsn = %sysfunc(countw(&dsn_lst)); %do i = 1 %to &n_dsn; proc contents data=&domain..%scan(&dsn_lst, &i) out=contents&i noprint; run; %end; data contents; set contents1-contents&n_dsn; run; proc datasets nolist memtype=data lib=work; delete contents1-contents%sysfunc(compress(&n_dsn)); quit; data contents; set contents(keep=libname memname memlabel name nobs); if upcase(name)="%upcase(&phin)"; run; data _null_; if 0 then set contents nobs=n; call symputx('nobs', n); stop; run; %if &nobs = 0 %then %do; %put WARNING: None of the selected tables had &phin variables; %put WARNING: Macro stop without generating any output; %return; %end; proc sql noprint; select memname, count(*) into :dsn_lst separated by ' ', :n_dsn from contents; quit; %do i = 1 %to &n_dsn; data %scan(&dsn_lst, &i); set &domain..%scan(&dsn_lst, &i)(keep=&type &phin &bydate); Year=put(&bydate, fy.); if year ^= 'Other Years'; if &type in ('0','1','2','3','6') then link=1; else link = 0; run; proc sort data=%scan(&dsn_lst, &i); by year; run; proc freq data=%scan(&dsn_lst, &i)(keep=link year) noprint; tables link/missing out=link&i(drop=count where=(link=1) /*rename=(percent=%scan(&dsn_lst, &i))*/); by year; run; data link&i; drop percent; set link&i; %scan(&dsn_lst, &i) = input(put(percent, 4.1), 8.); run; proc datasets nolist memtype=data lib=work; delete %scan(&dsn_lst, &i); quit; %end; data linkability_over_years; drop link; merge link1-link%sysfunc(compress(&n_dsn)); by year; run; %if %substr(&dq_dir, %length(&dq_dir), 1) = \ %then %let dq_dir = %substr(&dq_dir, 1, %length(&dq_dir) - 1); %if %substr(&sysscpl, 1, 3) = X64 or %substr(&sysscpl, 1, 3) = W64 %then %let dbms = excelcs; %else %let dbms = excel; proc export data=linkability_over_years outfile="&dq_dir\&dq_name..xls" dbms=&dbms replace; sheet = 'linkability_over_years'; run; proc datasets nolist memtype=data lib=work; delete link1-link%sysfunc(compress(&n_dsn)) contents; quit; proc print data=linkability_over_years; run; %mend dq_linkyr;