Я пытаюсь извлечь одну таблицу из oracle в SAS, используя три взаимосвязанных запроса, приведенных ниже, но последний не генерирует никаких выходных данных. Я просматривал код много раз, но я не нашел ошибку. Не могли бы вы мне помочь?
Первый запрос
%include "/sasusers/&sysuserid/gedspla.sas";
libname Guik "/lidata_br/atuaria/dmatuarial/vida/GKK";
%let produtos='93030', '93028', '77021', '77022', '77023', '77024', '77025', '77033', '77034', '77035', '77036', '77037', '77038', '77039', '77040', '77041', '77042';
*%let meses=202003, 202002, 202001, 201912, 201911, 201910, 201909, 201908, 201907, 201906, 201905, 201904, 201903, 201902, 201901, 201812, 201811, 201810, 201809, 201808, 201807, 201806, 201805, 201804, 201803;
%let meses=202003;
proc sql ;
connect to oracle(user=&d_usuario pass=&pass_dtm path='@dtm' preserve_comments);
create table Guik.tabela1 (compress=yes reuse=yes) as
select * from connection to oracle
(
select a11.DCTI_DTON_COD_ATF DTON_COD_ATF,
a11.DCTI_DDTC_COD_ATF DDTC_COD_ATF,
a12.DHCT_TSPR_COD DHCT_TSPR_COD,
a11.DCTI_DSDC_COD_ATF DSDC_COD_ATF,
a11.DCTI_DDSC_COD_ATF DDSC_COD_ATF,
a12.DHCT_IND_ROB DHCT_IND_ROB,
a12.DHCT_NUM_PRA DHCT_NUM_PRA,
a11.DCTI_DPRD_COD_PRD DPRD_COD_PRD,
a12.DHCT_NUM_CTC DHCT_NUM_CTC,
a12.DHCT_CTRS_COD DHCT_CTRS_COD,
a12.DHCT_DCSN_MCL DCSN_COD_ATF,
a12.DHCT_IND_ULT_CTC DHCT_IND_ULT_CTC,
a11.DCTI_DMID_COD_ATF DMID_COD_ATF,
a17.DFCL_DFFL_COD_ATF DFFL_COD_ATF,
a11.DCTI_DCLD_RFR_COD_ATF DCLD_COD_ATF,
a12.DHCT_DCLD_DAT_PRA DCLD_COD_ATF0,
a12.DHCT_DCLD_PRI_RCU DCLD_COD_ATF1,
a12.DHCT_DCLD_DAT_CTC DHCT_DCLD_DAT_CTC,
a11.DCTI_DCLD_INI_VGC_COD_ATF DCLD_COD_ATF2,
a11.DCTI_DCLD_FIM_VGC_COD_ATF DCLD_COD_ATF3,
a11.DCTI_DCLD_CRC_COD_ATF DCLD_COD_ATF4,
a12.DHCT_DSIT_COD_ATF DSIT_COD_ATF,
a11.DCTI_DCEP_COD_ATF DCEP_COD_ATF,
a12.DHCT_NUM_APO DMBE_APO_NUM,
sum(a11.DCTI_QTD_ITM) WJXBFS1,
sum(a11.DCTI_MRI_NGC_CTC) WJXBFS2
from
DMD_ITM_CTC a11
join DMD_HIS_CTC a12 on (a11.DCTI_DHCT_COD_ATF = a12.DHCT_COD_ATF)
join DMD_HIS_CTC a13 on (a11.DCTI_DHCT_COD_ATF = a13.DHCT_COD_ATF and a12.DHCT_DCLD_DAT_CTC = a13.DHCT_DCLD_DAT_CTC and a12.DHCT_IND_ROB = a13.DHCT_IND_ROB)
join DMF_PRD a14 on (a11.DCTI_DFPR_COD_ATF = a14.DFPR_COD_ATF)
join DMF_AGU_PRD a15 on (a14.DFPR_DFAP_COD_ATF = a15.DFAP_COD_ATF)
join DMC_CRT a16 on (a12.DHCT_DCRT_COD_CLI_OPN_CRT = a16.DCRT_COD_CLI_OPN_CRT)
join DMF_CEL a17 on (a16.DCRT_DFCL_COD_ATF = a17.DFCL_COD_ATF)
where
(((a15.DFAP_DFCP_COD_ATF) in (select c21.DFCP_COD_ATF from DMF_CAT_PRD c21 where c21.DFCP_DFSP_COD_ATF in (2426, 2430, 7781, 2427)))
and TO_NUMBER(TO_CHAR(TO_DATE(a12.DHCT_DCLD_DAT_CTC, 'YYYYMMDD'), 'YYYYMM')) in (&meses)
and a11.DCTI_DPRD_COD_PRD in (&produtos)
and a12.DHCT_IND_ULT_CTC in ('S')
and a12.DHCT_DCRT_COD_CLI_OPN_CRT not in (99040067))
group by a11.DCTI_DTON_COD_ATF,
a11.DCTI_DDTC_COD_ATF,
a12.DHCT_TSPR_COD,
a11.DCTI_DSDC_COD_ATF,
a11.DCTI_DDSC_COD_ATF,
a12.DHCT_IND_ROB,
a12.DHCT_NUM_PRA,
a11.DCTI_DPRD_COD_PRD,
a12.DHCT_NUM_CTC,
a12.DHCT_CTRS_COD,
a12.DHCT_DCSN_MCL,
a12.DHCT_IND_ULT_CTC,
a11.DCTI_DMID_COD_ATF,
a17.DFCL_DFFL_COD_ATF,
a11.DCTI_DCLD_RFR_COD_ATF,
a12.DHCT_DCLD_DAT_PRA,
a12.DHCT_DCLD_PRI_RCU,
a12.DHCT_DCLD_DAT_CTC,
a11.DCTI_DCLD_INI_VGC_COD_ATF,
a11.DCTI_DCLD_FIM_VGC_COD_ATF,
a11.DCTI_DCLD_CRC_COD_ATF,
a12.DHCT_DSIT_COD_ATF,
a11.DCTI_DCEP_COD_ATF,
a12.DHCT_NUM_APO );
;
disconnect from oracle;
quit;
Второй запрос
proc sql ;
connect to oracle(user=&d_usuario pass=&pass_dtm path='@dtm' preserve_comments);
create table Guik.tabela2 (compress=yes reuse=yes) as
select * from connection to oracle
(
select a11.DCTI_DTON_COD_ATF DTON_COD_ATF,
a11.DCTI_DDTC_COD_ATF DDTC_COD_ATF,
a12.DHCT_TSPR_COD DHCT_TSPR_COD,
a11.DCTI_DSDC_COD_ATF DSDC_COD_ATF,
a11.DCTI_DDSC_COD_ATF DDSC_COD_ATF,
a12.DHCT_IND_ROB DHCT_IND_ROB,
a12.DHCT_NUM_PRA DHCT_NUM_PRA,
a11.DCTI_DPRD_COD_PRD DPRD_COD_PRD,
a12.DHCT_NUM_CTC DHCT_NUM_CTC,
a12.DHCT_CTRS_COD DHCT_CTRS_COD,
a12.DHCT_DCSN_MCL DCSN_COD_ATF,
a12.DHCT_IND_ULT_CTC DHCT_IND_ULT_CTC,
a11.DCTI_DMID_COD_ATF DMID_COD_ATF,
a17.DFCL_DFFL_COD_ATF DFFL_COD_ATF,
a11.DCTI_DCLD_RFR_COD_ATF DCLD_COD_ATF,
a12.DHCT_DCLD_DAT_PRA DCLD_COD_ATF0,
a12.DHCT_DCLD_PRI_RCU DCLD_COD_ATF1,
a12.DHCT_DCLD_DAT_CTC DHCT_DCLD_DAT_CTC,
a11.DCTI_DCLD_INI_VGC_COD_ATF DCLD_COD_ATF2,
a11.DCTI_DCLD_FIM_VGC_COD_ATF DCLD_COD_ATF3,
a11.DCTI_DCLD_CRC_COD_ATF DCLD_COD_ATF4,
a12.DHCT_DSIT_COD_ATF DSIT_COD_ATF,
a11.DCTI_DCEP_COD_ATF DCEP_COD_ATF,
a12.DHCT_NUM_APO DMBE_APO_NUM,
sum(a11.DCTI_QTD_ITM) WJXBFS1
from DMD_ITM_CTC a11
join DMD_HIS_CTC a12
on (a11.DCTI_DHCT_COD_ATF = a12.DHCT_COD_ATF)
join DMD_HIS_CTC a13
on (a11.DCTI_DHCT_COD_ATF = a13.DHCT_COD_ATF and
a12.DHCT_DCLD_DAT_CTC = a13.DHCT_DCLD_DAT_CTC and
a12.DHCT_IND_ROB = a13.DHCT_IND_ROB)
join DMF_PRD a14
on (a11.DCTI_DFPR_COD_ATF = a14.DFPR_COD_ATF)
join DMF_AGU_PRD a15
on (a14.DFPR_DFAP_COD_ATF = a15.DFAP_COD_ATF)
join DMC_CRT a16
on (a12.DHCT_DCRT_COD_CLI_OPN_CRT = a16.DCRT_COD_CLI_OPN_CRT)
join DMF_CEL a17
on (a16.DCRT_DFCL_COD_ATF = a17.DFCL_COD_ATF)
where (((a15.DFAP_DFCP_COD_ATF)
in (select c21.DFCP_COD_ATF
from DMF_CAT_PRD c21
where c21.DFCP_DFSP_COD_ATF in (2426, 2430, 7781, 2427)))
and TO_NUMBER(TO_CHAR(TO_DATE(a12.DHCT_DCLD_DAT_CTC, 'YYYYMMDD'), 'YYYYMM')) in (202003, 202002, 202001, 201912, 201911, 201910, 201909, 201908, 201907, 201906, 201905, 201904, 201903, 201902, 201901, 201812, 201811, 201810, 201809, 201808, 201807, 201806, 201805, 201804, 201803)
and a11.DCTI_DPRD_COD_PRD in ('93030', '93028', '77021', '77022', '77023', '77024', '77025', '77033', '77034', '77035', '77036', '77037', '77038', '77039', '77040', '77041', '77042')
and a12.DHCT_IND_ULT_CTC in ('S')
and a12.DHCT_DCRT_COD_CLI_OPN_CRT not in (99040067)
and a11.DCTI_DDSC_COD_ATF in (3))
group by a11.DCTI_DTON_COD_ATF,
a11.DCTI_DDTC_COD_ATF,
a12.DHCT_TSPR_COD,
a11.DCTI_DSDC_COD_ATF,
a11.DCTI_DDSC_COD_ATF,
a12.DHCT_IND_ROB,
a12.DHCT_NUM_PRA,
a11.DCTI_DPRD_COD_PRD,
a12.DHCT_NUM_CTC,
a12.DHCT_CTRS_COD,
a12.DHCT_DCSN_MCL,
a12.DHCT_IND_ULT_CTC,
a11.DCTI_DMID_COD_ATF,
a17.DFCL_DFFL_COD_ATF,
a11.DCTI_DCLD_RFR_COD_ATF,
a12.DHCT_DCLD_DAT_PRA,
a12.DHCT_DCLD_PRI_RCU,
a12.DHCT_DCLD_DAT_CTC,
a11.DCTI_DCLD_INI_VGC_COD_ATF,
a11.DCTI_DCLD_FIM_VGC_COD_ATF,
a11.DCTI_DCLD_CRC_COD_ATF,
a12.DHCT_DSIT_COD_ATF,
a11.DCTI_DCEP_COD_ATF,
a12.DHCT_NUM_APO )
;
disconnect from oracle;
quit;
Третий запрос (проблема). OBS: не появляется никаких ошибок, связанных с кодом в журнале. Я бы ничего не показывал. Работает нормально.
proc sql ;
connect to oracle(user=&d_usuario pass=&pass_dtm path='@dtm' preserve_comments);
create table Guik.tabela3 (compress=yes reuse=yes) as
select * from connection to oracle
(
select distinct coalesce(pa11.DHCT_NUM_CTC, pa12.DHCT_NUM_CTC) DHCT_NUM_CTC,
coalesce(pa11.DTON_COD_ATF, pa12.DTON_COD_ATF) DTON_COD_ATF,
FN_MSTR_CHR_SET(a121.DTON_DES) DTON_DES,
coalesce(pa11.DDTC_COD_ATF, pa12.DDTC_COD_ATF) DDTC_COD_ATF,
a120.DDTC_DES DDTC_DES,
coalesce(pa11.DDSC_COD_ATF, pa12.DDSC_COD_ATF) DDSC_COD_ATF,
FN_MSTR_CHR_SET(a117.DDSC_DES) DDSC_DES,
coalesce(pa11.DSDC_COD_ATF, pa12.DSDC_COD_ATF) DSDC_COD_ATF,
a118.DSDC_DES DSDC_DES,
coalesce(pa11.DHCT_NUM_PRA, pa12.DHCT_NUM_PRA) DHCT_NUM_PRA,
coalesce(pa11.DHCT_TSPR_COD, pa12.DHCT_TSPR_COD) DHCT_TSPR_COD,
a119.TSPR_DES DHCT_TSPR_DES,
coalesce(pa11.DCSN_COD_ATF, pa12.DCSN_COD_ATF) DCSN_COD_ATF,
a115.DCSN_COD_SOG DCSN_COD_SOG,
coalesce(pa11.DHCT_IND_ROB, pa12.DHCT_IND_ROB) DHCT_IND_ROB,
coalesce(pa11.DHCT_IND_ULT_CTC, pa12.DHCT_IND_ULT_CTC) DHCT_IND_ULT_CTC,
coalesce(pa11.DMID_COD_ATF, pa12.DMID_COD_ATF) DMID_COD_ATF,
a114.DMID_DES DMID_DES,
coalesce(pa11.DSIT_COD_ATF, pa12.DSIT_COD_ATF) DSIT_COD_ATF,
a17.DSIT_DES DSIT_DES,
coalesce(pa11.DMBE_APO_NUM, pa12.DMBE_APO_NUM) DMBE_APO_NUM,
coalesce(pa11.DHCT_CTRS_COD, pa12.DHCT_CTRS_COD) DHCT_CTRS_COD,
coalesce(pa11.DCEP_COD_ATF, pa12.DCEP_COD_ATF) DCEP_COD_ATF,
a16.DCEP_COD_CEP_REZ DCEP_COD_CEP_REZ,
coalesce(pa11.DCLD_COD_ATF, pa12.DCLD_COD_ATF) DCLD_COD_ATF,
a113.DCLD_DAT DCLD_DAT,
coalesce(pa11.DCLD_COD_ATF0, pa12.DCLD_COD_ATF0) DCLD_COD_ATF0,
a112.DCLD_DAT DCLD_DAT0,
coalesce(pa11.DCLD_COD_ATF1, pa12.DCLD_COD_ATF1) DCLD_COD_ATF1,
a111.DCLD_DAT DCLD_DAT1,
coalesce(pa11.DCLD_COD_ATF2, pa12.DCLD_COD_ATF2) DCLD_COD_ATF2,
a110.DCLD_DAT DCLD_DAT2,
coalesce(pa11.DCLD_COD_ATF3, pa12.DCLD_COD_ATF3) DCLD_COD_ATF3,
a19.DCLD_DAT DCLD_DAT3,
coalesce(pa11.DHCT_DCLD_DAT_CTC, pa12.DHCT_DCLD_DAT_CTC) DHCT_DCLD_DAT_CTC,
a14.DCLD_DAT DCLD_DAT4,
coalesce(pa11.DCLD_COD_ATF4, pa12.DCLD_COD_ATF4) DCLD_COD_ATF4,
a18.DCLD_DAT DCLD_DAT5,
coalesce(pa11.DPRD_COD_PRD, pa12.DPRD_COD_PRD) DPRD_COD_PRD,
FN_MSTR_CHR_SET(a116.DPRD_NOM) DPRD_NOM,
a15.DFFL_DFRG_COD_ATF DFRG_COD_ATF,
FN_MSTR_CHR_SET(a123.DFRG_DES) DFRG_DES,
a14.DCLD_DMAN_COD_ATF DMAN_COD_ATF,
a122.DMAN_DES DMAN_DES,
coalesce(pa11.DFFL_COD_ATF, pa12.DFFL_COD_ATF) DFFL_COD_ATF,
FN_MSTR_CHR _SET(a15.DFFL_DES) DFFL_DES,
pa11.WJXBFS1 WJXBFS1,
pa12.WJXBFS1 WJXBFS2,
pa11.WJXBFS2 WJXBFS3
from Guik.tabela1 pa11
full outer join Guik.tabela2 pa12 on (pa11.DCEP_COD_ATF = pa12.DCEP_COD_ATF and
pa11.DCLD_COD_ATF = pa12.DCLD_COD_ATF and
pa11.DCLD_COD_ATF0 = pa12.DCLD_COD_ATF0 and
pa11.DCLD_COD_ATF1 = pa12.DCLD_COD_ATF1 and
pa11.DCLD_COD_ATF2 = pa12.DCLD_COD_ATF2 and
pa11.DCLD_COD_ATF3 = pa12.DCLD_COD_ATF3 and
pa11.DCLD_COD_ATF4 = pa12.DCLD_COD_ATF4 and
pa11.DCSN_COD_ATF = pa12.DCSN_COD_ATF and
pa11.DDSC_COD_ATF = pa12.DDSC_COD_ATF and
pa11.DDTC_COD_ATF = pa12.DDTC_COD_ATF and
pa11.DFFL_COD_ATF = pa12.DFFL_COD_ATF and
pa11.DHCT_CTRS_COD = pa12.DHCT_CTRS_COD and
pa11.DHCT_DCLD_DAT_CTC = pa12.DHCT_DCLD_DAT_CTC and
pa11.DHCT_IND_ROB = pa12.DHCT_IND_ROB and
pa11.DHCT_IND_ULT_CTC = pa12.DHCT_IND_ULT_CTC and
pa11.DHCT_NUM_CTC = pa12.DHCT_NUM_CTC and
pa11.DHCT_NUM_PRA = pa12.DHCT_NUM_PRA and
pa11.DHCT_TSPR_COD = pa12.DHCT_TSPR_COD and
pa11.DMBE_APO_NUM = pa12.DMBE_APO_NUM and
pa11.DMID_COD_ATF = pa12.DMID_COD_ATF and
pa11.DPRD_COD_PRD = pa12.DPRD_COD_PRD and
pa11.DSDC_COD_ATF = pa12.DSDC_COD_ATF and
pa11.DSIT_COD_ATF = pa12.DSIT_COD_ATF and
pa11.DTON_COD_ATF = pa12.DTON_COD_ATF)
join DMC_CLD a14 on (coalesce(pa11.DHCT_DCLD_DAT_CTC, pa12.DHCT_DCLD_DAT_CTC) = a14.DCLD_COD_ATF)
join DMF_FIL a15 on (coalesce(pa11.DFFL_COD_ATF, pa12.DFFL_COD_ATF) = a15.DFFL_COD_ATF)
join DMM_CEP a16 on (coalesce(pa11.DCEP_COD_ATF, pa12.DCEP_COD_ATF) = a16.DCEP_COD_ATF)
join DMD_STM_ORI a17 on (coalesce(pa11.DSIT_COD_ATF, pa12.DSIT_COD_ATF) = a17.DSIT_COD_ATF)
join DMC_CLD a18 on (coalesce(pa11.DCLD_COD_ATF4, pa12.DCLD_COD_ATF4) = a18.DCLD_COD_ATF)
join DMC_CLD a19 on (coalesce(pa11.DCLD_COD_ATF3, pa12.DCLD_COD_ATF3) = a19.DCLD_COD_ATF)
join DMC_CLD a110 on (coalesce(pa11.DCLD_COD_ATF2, pa12.DCLD_COD_ATF2) = a110.DCLD_COD_ATF)
join DMC_CLD a111 on (coalesce(pa11.DCLD_COD_ATF1, pa12.DCLD_COD_ATF1) = a111.DCLD_COD_ATF)
join DMC_CLD a112 on (coalesce(pa11.DCLD_COD_ATF0, pa12.DCLD_COD_ATF0) = a112.DCLD_COD_ATF)
join DMC_CLD a113 on (coalesce(pa11.DCLD_COD_ATF, pa12.DCLD_COD_ATF) = a113.DCLD_COD_ATF)
join DMM_IDD a114 on (coalesce(pa11.DMID_COD_ATF, pa12.DMID_COD_ATF) = a114.DMID_COD_ATF)
join DMC_SIM_NAO a115 on (coalesce(pa11.DCSN_COD_ATF, pa12.DCSN_COD_ATF) = a115.DCSN_COD_ATF)
join DMC_PRD a116 on (coalesce(pa11.DPRD_COD_PRD, pa12.DPRD_COD_PRD) = a116.DPRD_COD_PRD)
join DMD_STS_CTC a117 on (coalesce(pa11.DDSC_COD_ATF, pa12.DDSC_COD_ATF) = a117.DDSC_COD_ATF)
join DMD_STS_DTL_CTC a118 on (coalesce(pa11.DSDC_COD_ATF, pa12.DSDC_COD_ATF) = a118.DSDC_COD_ATF)
join (SELECT distinct DHCT_TSPR_COD TSPR_COD,
DHCT_TSPR_DES TSPR_DES
FROM DMD_HIS_CTC) a119 on (coalesce(pa11.DHCT_TSPR_COD, pa12.DHCT_TSPR_COD) = a119.TSPR_COD)
join DMD_TIP_CTC a120 on (coalesce(pa11.DDTC_COD_ATF, pa12.DDTC_COD_ATF) = a120.DDTC_COD_ATF)
join DMC_TIP_ORI_NGC a121 on (coalesce(pa11.DTON_COD_ATF, pa12.DTON_COD_ATF) = a121.DTON_COD_ATF)
join DMC_MES_ANO a122 on (a14.DCLD_DMAN_COD_ATF = a122.DMAN_COD_ATF)
join DMF_RGI a123 on (a15.DFFL_DFRG_COD_ATF = a123.DFRG_COD_ATF)
;
disconnect from oracle;
quit;