在proc SQL

时间:2018-11-03 03:41:23

标签: sql proc-sql case-statement

我想编写多个case语句并创建在同一proc sql代码中创建的多个新变量(此处的新var为dob_match)。能做到吗? 否则,我必须编写多个此类proc sql代码段,然后将这些表连接在一起。但是,这些巨大的表正在加入4-5个巨大的表,这在我的计算机上遇到了时空问题。

有人可以建议在SAS中执行此操作的任何有效方法(每个表约有20万行)。

谢谢。

基本上,我想做—

proc sql

创建表匹配项为

( 选择修正,pdd。

案例 然后,否则<>以NEW_VARIABLE 1

结尾

案例 然后,否则<>以NEW_VARIABLE 2结尾 。 。 。 案件 然后,否则<>以NEW_VARIABLE 6

结尾

from newlink.CORC_uprob as corc
完整的JOIN WORK.unmatchpdd作为pdd 上 corc.hospitalid2 = pdd.oshpdid2

);

退出;

我的SAS代码是-

 proc sql; 
create
table DOB_match as 

(
select corc.Medrecn as MRN, pdd.SSN as pSSN, corc.birthdate as corcbday, pdd.bthdate as pddbday, corc.newIDCORC as newIDCORC, pdd.newIDPDD as newIDPDD, 
corc.hospitalid2 as corcHosp, pdd.oshpdid2 as pddhosp,
corc.dischargedate as dsdt_corc, pdd.dschdate as dsdt_pdd, corc.Surgdate as Surgdt_corc, pdd.PDDCABGSurgDt as Surgdt_pdd,
corc.*, pdd.*,


case 

when corc.day = pdd.day and corc.month = pdd.month and corc.year = pdd.year then 100
else -10 end as dob_match

from newlink.CORC_uprob as corc   
full JOIN WORK.unmatchpdd as pdd
on
corc.hospitalid2 = pdd.oshpdid2 ); 

quit; 

1 个答案:

答案 0 :(得分:0)

我知道了。

    proc sql; 
   create
   table DOB_match as 

  (
 select corc.Medrecn as MRN, pdd.SSN as pSSN, corc.birthdate as corcbday,     pdd.bthdate as pddbday, corc.newIDCORC as newIDCORC, pdd.newIDPDD as   newIDPDD, 
 corc.hospitalid2 as corcHosp, pdd.oshpdid2 as pddhosp,
corc.dischargedate as dsdt_corc, pdd.dschdate as dsdt_pdd, corc.Surgdate       as Surgdt_corc, pdd.PDDCABGSurgDt as Surgdt_pdd,
corc.*, pdd.*,


case 
when corc.day = pdd.day and corc.month = pdd.month and corc.year =      pdd.year then 100
 else -10 end as dob_match,

 case 
 when corc.x = pdd.y then 100
else -10 end as test



from newlink.CORC_uprob as corc   
full JOIN WORK.unmatchpdd as pdd
 on
corc.hospitalid2 = pdd.oshpdid2 ); 

 quit;