2015-09-24 33 views
-1

我需要使此代碼更高效(請參閱下文)。代碼正在做的是僅在「統一」中缺少觀察值的情況下,使用「均值」中的值更新「統一」主數據集。這會通過並更新16個變量。PROC SQL UPDATE - 效率

有沒有辦法讓這個更有效,如創建通過16個變量的循環?

proc sql; 
update index.consolidated as a 
set GRANTS_3YP = case when a.GRANTS_3YP ^= . then a.GRANTS_3YP else (select GRANTS_3YP from index.means as b where a.LGA = b.LGA) end, 
    GRANTS_3Y = case when a.GRANTS_3Y ^= . then a.GRANTS_3Y else (select GRANTS_3Y from index.means as b where a.LGA = b.LGA) end, 
    RI_GEN = case when a.RI_GEN ^= . then a.RI_GEN else (select RI_GEN from index.means as b where a.LGA = b.LGA) end, 
    FIFO = case when a.FIFO ^= . then a.FIFO else (select FIFO from index.means as b where a.LGA = b.LGA) end, 
    YU_3Y = case when a.YU_3Y ^= . then a.YU_3Y else (select YU_3Y from index.means as b where a.LGA = b.LGA) end, 
    POP_FLOWS = case when a.POP_FLOWS ^= . then a.POP_FLOWS else (select POP_FLOWS from index.means as b where a.LGA = b.LGA) end, 
    COL = case when a.COL ^= . then a.COL else (select COL from index.means as b where a.LGA = b.LGA) end, 
    IC = case when a.IC ^= . then a.IC else (select IC from index.means as b where a.LGA = b.LGA) end, 
    DISTANCE = case when a.DISTANCE ^= . then a.DISTANCE else (select DISTANCE from index.means as b where a.LGA = b.LGA) end, 
    MR_3Y = case when a.MR_3Y ^= . then a.MR_3Y else (select MR_3Y from index.means as b where a.LGA = b.LGA) end, 
    MP = case when a.MP ^= . then a.MP else (select MP from index.means as b where a.LGA = b.LGA) end, 
    DP = case when a.DP ^= . then a.DP else (select DP from index.means as b where a.LGA = b.LGA) end, 
    RENT = case when a.RENT ^= . then a.RENT else (select RENT from index.means as b where a.LGA = b.LGA) end, 
    DEATH = case when a.DEATH ^= . then a.DEATH else (select DEATH from index.means as b where a.LGA = b.LGA) end, 
    MENTAL = case when a.MENTAL ^= . then a.MENTAL else (select MENTAL from index.means as b where a.LGA = b.LGA) end, 
    AGE = case when a.AGE ^= . then a.AGE else (select AGE from index.means as b where a.LGA = b.LGA) end; 
quit; 

回答

0

您的查詢將花費太多時間,因爲你是在同一時間更新16條記錄,然後您使用子查詢中每一組。

我的建議是使用JOIN(INNER/LEFT/RIGHT),似乎你在每個SET中的子查詢包含相同的表index.means。只需將身份加入您的表格即可。