简体   繁体   English

SQL case 语句,使用 IF、THEN DO 将此 SAS 代码转换为 SQL 脚本

[英]SQL case statement that converts this SAS code using IF, THEN DO, into SQL script

I need to do this for work as we are transforming some of our SAS programs into SQL as part of an ongoing project.我需要这样做,因为我们正在将一些 SAS 程序转换为 SQL 作为正在进行的项目的一部分。 This is the SAS code that I need to change into SQL case statement:这是我需要更改为 SQL 案例语句的 SAS 代码:

if Patients1 in (08,09,10) or (Patients1=41 and HospAttend=' Yes') then do;
        if Patients2 ne 23 then AdmitResult='1. Patient Type A';
        else if Patients2 =23 then AdmitResult='2. Patient Type B';
    end;

Any help is greatly appreciated!任何帮助是极大的赞赏!

As a case expression this would be:作为一个case表达式,这将是:

(case when Patients1 in ('08', '09', '10') or
           (Patients1 = '41' and HospAttend = ' Yes') 
      then (case when Patients2 <> 23 then '1. Patient Type A';
                 else '2. Patient Type B'
            end)
 end) as AdmitResult;

Note: The leading zeros on Patients1 suggest that the values are strings.注意: Patients1上的前导零表示这些值是字符串。 If they are numbers, remove both the single quotes and the leading zeros (the leading zeros are misleading in that case).如果它们是数字,请删除单引号和前导零(在这种情况下,前导零会产生误导)。

Also, the space in ' Yes' is meaningful and you might not really need it.此外, ' Yes'中的空格是有意义的,您可能并不真正需要它。 Strings are not usually stored with leading spaces.字符串通常不使用前导空格存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM