Created
October 25, 2018 14:14
-
-
Save rpardee/2b15563086395a3eab386bb859078bfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Translate service centers to facility codes. Translations change over time. ; | |
data svc_facs ; | |
input | |
@1 svcctr $char3. | |
@7 ctreffdt date9. | |
@19 ctrtrmdt date9. | |
@31 facility_code $char3. | |
; | |
format ctr: mmddyy10. ; | |
datalines ; | |
003 01jan2000 31dec2000 xxx | |
003 01jan2001 31dec2001 yyy | |
003 01jan2002 31dec2002 zzz | |
; | |
run ; | |
proc print ; | |
run ; | |
* Service charge records have service centers (locations) and service dates. ; | |
data have ; | |
input | |
@1 svcctr $char3. | |
@5 servicedt date9. | |
@15 should_be $char3. | |
; | |
format servicedt mmddyy10. ; | |
datalines ; | |
003 30jun2000 xxx | |
003 30jun2001 yyy | |
003 30jun2002 zzz | |
003 30jun2003 003 <-- outside any given period--dont translate NOT WORKING | |
003 28apr2000 xxx | |
033 30jun2001 033 <-- service center not in translation table--dont translate | |
; | |
run ; | |
proc print ; | |
run ; | |
* Add facility codes to the service charges, based on center and date. ; | |
data want ; | |
length facility_code should_be $ 3 ; | |
set have ; | |
if _n_ = 1 then do ; | |
declare hash svctofac(dataset: 'svc_facs', multidata: 'y') ; | |
svctofac.definekey('svcctr') ; | |
svctofac.definedata('svcctr', 'ctreffdt', 'ctrtrmdt', 'facility_code') ; | |
svctofac.definedone() ; | |
call missing (ctreffdt, ctrtrmdt, facility_code) ; | |
end ; | |
svctofac.reset_dup() ; * <-- necessary? its in all the examples... ; | |
do while(svctofac.do_over(key:svcctr) = 0) ; | |
if ctreffdt le servicedt le ctrtrmdt then do ; | |
put svcctr= servicedt= ctreffdt= ctrtrmdt= facility_code= ; | |
leave ; | |
end ; | |
end ; | |
* if we escape that loop w/out getting a value in facility_code we didnt find a translation--just use svcctr ; | |
if cmiss(facility_code) = 1 then facility_code = svcctr ; | |
format ctr: mmddyy10. ; | |
* drop ctr: ; | |
run ; | |
proc print ; | |
run ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment