proc sql;
create table work.EXUPL_GVA2_&YYMM. as
select R.*,
S.FIL as FILMAP, S.KTO as KTOMAP
from work.EXUPL_GVA1_&YYMM. as R
left join LIB_CLNT.CLIENT2SEGMENT_FKN_FINAL_&YYMM.
(where =( FIL and KTO <=0)) as S
on R.ORG_ID=S.ORG_ID
;
quit;
data work.EXUPL_GVA3_&YYMM.;
set work.EXUPL_GVA2_&YYMM.;
if KTO eq 9999989 and KTOMAP not in (. 9999989) then do;
FIL=FILMAP;
KTO=KTOMAP;
end;
run;
proc sql;
create table work.EXUPL_GVA4_&YYMM. as
select R.*
,S.PCC
,S.GBM
from work.EXUPL_GVA2_&YYMM. as R
left join LIB_CLNT.CLIENT_MASTER_&YYMM. as S
on R.FIL=S.FIL and R.KTO=S.KTO
;
quit;