我需要提高此代码的效率(请参阅下文)。代码正在做的是更新主数据集'合并'来自'的价值观'只有在观察到的情况下才能巩固'不见了。这将通过并更新16个变量。
有没有办法提高效率,例如在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 :(得分:0)
您的查询将花费太多时间,因为您正在同时更新16条记录,然后您在每个SET中使用子查询。
我的建议是使用JOIN(INNER / LEFT / RIGHT),似乎每个SET中的子查询包含相同的表index.means
。只需加入一个标识即可加入您的表格。