我正在嘗試創建在 sas 中到 postgressql 的表,但我無法理解此 sas 代碼的作用。這是我的代碼:-
DATA work."WC7I7AHE"n
(keep = "DMMCU"n "DMITM"n "DMVEND"n "IBVEND"n "IBVEND_1110"n )
;
attrib "DMMCU"n length=$12 format=$12. label="Business Unit"
"DMITM"n length=8 format=8. label="Item Number - Short"
"DMVEND"n length=8 format=8. label="Supplier Number"
"IBVEND"n length=8 format=8. label="Supplier Number"
"IBVEND_1110"n length=8 format=8. label="Supplier Number"
"IBITM"n length= 8
"IBMCU"n length= $12
ETLS_W2NX3KTY4 length= 8
;
retain missing0-missing1 0;
etls_assign_target_value = 0;
/* Build hash objects from lookup tables before reading first source row */
if (_n_ = 1) then
do;
/* Build hash h0 from lookup table etls_temp_lookupview0 */
nlobs = .;
dsid = open("etls_temp_lookupview0");
if (dsid > 0) then
do;
if ( attrc(dsid, 'MTYPE') = 'DATA' ) then
nlobs = attrn(dsid, 'NLOBS');
else
nlobs = -1;
dsid = close(dsid);
if (nlobs ^= 0) then
do;
if (nlobs > 0) then
exponent = ceil(log2(nlobs));
else
exponent = 8;
declare hash h0(dataset: "etls_temp_lookupview0", hashexp: exponent);
h0.defineKey( "IBITM",
"IBMCU");
h0.defineData( "IBVEND");
h0.defineDone();
if (nlobs = -1) then
do;
if (h0.Num_Items < 1) then
do;
put "NOTE: Lookup table is empty: etls_temp_lookupview0";
put "NOTE: Abort action indicated, condition= Lookup table is empty:"
" etls_temp_lookupview0";
abort 3;
end;
end;
end;
else
do;
put "NOTE: Lookup table is empty: etls_temp_lookupview0";
put "NOTE: Abort action indicated, condition= Lookup table is empty:"
" etls_temp_lookupview0";
abort 3;
end;
end;
else
do;
put "NOTE: Lookup table does not exist or cannot be opened:"
" etls_temp_lookupview0";
put "NOTE: Abort action indicated, condition= Lookup table missing:"
" etls_temp_lookupview0";
abort 3;
end;
/* Build hash h1 from lookup table etls_temp_lookupview1 */
nlobs = .;
dsid = open("etls_temp_lookupview1");
if (dsid > 0) then
do;
if ( attrc(dsid, 'MTYPE') = 'DATA' ) then
nlobs = attrn(dsid, 'NLOBS');
else
nlobs = -1;
dsid = close(dsid);
if (nlobs ^= 0) then
do;
if (nlobs > 0) then
exponent = ceil(log2(nlobs));
else
exponent = 8;
declare hash h1(dataset: "etls_temp_lookupview1", hashexp: exponent);
h1.defineKey( "IBITM");
h1.defineData( "ETLS_W2NX3KTY4");
h1.defineDone();
if (nlobs = -1) then
do;
if (h1.Num_Items < 1) then
do;
put "NOTE: Lookup table is empty: etls_temp_lookupview1";
put "NOTE: Abort action indicated, condition= Lookup table is empty:"
" etls_temp_lookupview1";
abort 3;
end;
end;
end;
else
do;
put "NOTE: Lookup table is empty: etls_temp_lookupview1";
put "NOTE: Abort action indicated, condition= Lookup table is empty:"
" etls_temp_lookupview1";
abort 3;
end;
end;
else
do;
put "NOTE: Lookup table does not exist or cannot be opened:"
" etls_temp_lookupview1";
put "NOTE: Abort action indicated, condition= Lookup table missing:"
" etls_temp_lookupview1";
abort 3;
end;
call missing ("IBITM"n, "IBMCU"n, "IBVEND"n, "ETLS_W2NX3KTY4"n);
end; /* All hash objects have been defined */
/* Read a row from the source table */
set dmTBLS."DM_TURNOVER_TMP_VEND"n end = eof;
/* Is the current key value stored in hash h0? */
rc0 = h0.find(key: "DMITM"n,
key: "DMMCU"n);
/* Is the current key value stored in hash h1? */
rc1 = h1.find(key: "DMITM"n);
"IBVEND_1110"n = ETLS_W2NX3KTY4;
/* Examine success of lookups */
if ( rc0=0 and rc1=0 ) then
do;
/* Write row to target */
output work."WC7I7AHE"n;
Till now I understood this part only
使用這些列 dmmcu varchar(12)、dmitm int、dmvend int、ibvend int、ibvend_1110 int 創建表 turnoverrate_tm.wc7i7ahe
我不明白上面的 sas 代碼是做什么的。請解釋一下。
我不需要代碼,只需要邏輯
uj5u.com熱心網友回復:
從我的角度來看,當您使用查找節點時,這段代碼顯然來自 SAS Data Integration Studio,在本例中有兩個查找。因此,在 SAS DI Studio 中,您可以輕松地看出代碼的意圖,但以簡短的形式對其進行解釋:
這里主要的輸入表是dmTBLS.DM_TURNOVER_TMP_VEND。然后有兩次查找,一次針對表etls_temp_lookupview0,另一次查找表是etls_temp_lookupview1。對于這兩種查找,哈希都被定義為使用以下鍵查找值。在第一種情況下,鍵是 IBITM 和 IBMCU,而我們要查找的資料是 IBVEND。在第二種情況下,鍵是 IBITM,資料列是 ETLS_W2NX3KTY4,然后將其值放入列 IBVEND_1110。只有一些額外的錯誤例程是 SAS 使用查找節點創建的。最后,輸出表 work.WC7I7AHE 是用 keep 陳述句中的變數構建的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/537276.html
