编码 If -then 使用 CASE WHEN 语句从 SAS 到 SQL
Coding If -then do from SAS to SQL using CASE WHEN statement
我在 SAS 中有一段代码想用 SQL 编写。它使用 if-then do.
if x>0 and y>0 and z<0 then do
a=x
b=y+x
c=0
else if x<0 and y<0 and z>0 then do
a=0
b=-y
c=z
我想知道是否可以使用 CASE WHEN 语句在 SQL 中重新创建此类代码。 a、b、c 是创建的新列(变量)。 x、y、z 出现在我的 table 中。
对此的任何帮助将不胜感激。谢谢
您需要为每个要创建的变量执行一次,而不是按照以下几行的条件查看它:
case when X>0 & y>0 & z<0 then X
else when x<0 & y<0 & z>0 then 0
end as a,
case when X>0 & y>0 & z<0 then X+Y
else when x<0 & y<0 & z>0 then -Y
end as b,
case when X>0 & y>0 & z<0 then 0
else when x<0 & y<0 & z>0 then Z
end as c,
我在 SAS 中有一段代码想用 SQL 编写。它使用 if-then do.
if x>0 and y>0 and z<0 then do
a=x
b=y+x
c=0
else if x<0 and y<0 and z>0 then do
a=0
b=-y
c=z
我想知道是否可以使用 CASE WHEN 语句在 SQL 中重新创建此类代码。 a、b、c 是创建的新列(变量)。 x、y、z 出现在我的 table 中。 对此的任何帮助将不胜感激。谢谢
您需要为每个要创建的变量执行一次,而不是按照以下几行的条件查看它:
case when X>0 & y>0 & z<0 then X
else when x<0 & y<0 & z>0 then 0
end as a,
case when X>0 & y>0 & z<0 then X+Y
else when x<0 & y<0 & z>0 then -Y
end as b,
case when X>0 & y>0 & z<0 then 0
else when x<0 & y<0 & z>0 then Z
end as c,