使用 case when 语句覆盖/更新 proc sql 中的 af 变量值 [英] Override/update af variables value in proc sql using case when statement

查看:110
本文介绍了使用 case when 语句覆盖/更新 proc sql 中的 af 变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将变量从旧"数据集左连接到新"数据集.UFORM 变量的值为 25 或 ..如果左连接给了我.的值,我想用值0替换它.我不能在下面的sql语句中更新UFORM变量的值而不是制作UFORM2变量吗?

I want to left join a variable from an "old" dataset to a "new" dataset. The UFORM variable has the values 25 or .. If the left join gives me the value of ., I want to replace it with the value 0. Can't I update the value of the UFORM-variable in the following sql statement in stead of making the UFORM2 variable?

下面的语句有效,但我宁愿不使用 UFORM2 变量.

The statement below works, but I'd rather not make the UFORM2-variable.

proc sql;
   create table new as
   select X.*, Z.UFORM , case when Z.UFORM eq . then 0 else Z.UFORM end as UFORM2
   from old X
   left join info Z
   on X.value1 = Z.value1
   and X.value2 = Z.value2;
quit;

推荐答案

这是您想要的吗?

proc sql;
   create table new as
   select X.*, coalesce(Z.UFORM, 0) as UFROM
   from old X left join
        info Z
        on X.value1 = Z.value1 and
           X.value2 = Z.value2;
quit;

这篇关于使用 case when 语句覆盖/更新 proc sql 中的 af 变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆