如何在SAS中将多个单值输出组合成单行?

时间:2016-10-25 19:55:38

标签: sql formatting sas output

我正在计算多个范围的变量,并希望将它们全部聚合成一行。现在我将它们全部聚合到一个表中,其中对角线被填充但是对角线都是空的。我想保留我为每个计数分配的名字。我无法在网上找到描述如何做到这一点的内容。

以下是我的代码示例。

PROC SQL;
SELECT COUNT(loannumber) AS FICO_sub_620 
FROM tbl
WHERE LNFICO < 620

outer union

SELECT COUNT(loannumber) AS FICO_620_639
FROM tbl
WHERE LNFICO BETWEEN 620 AND 639

outer union

SELECT COUNT(loannumber) AS FICO_640_659
FROM tbl
WHERE LNFICO BETWEEN 640 AND 659

outer union

SELECT COUNT(loannumber) AS FICO_660_679
FROM tbl
WHERE LNFICO BETWEEN 660 AND 679;

RUN;

enter image description here

2 个答案:

答案 0 :(得分:1)

使用条件聚合:

PROC SQL;
    SELECT SUM(CASE WHEN LNFICO < 620 THEN 1 ELSE 0 END) AS FICO_sub_620,
           SUM(CASE WHEN LNFICO BETWEEN 620 AND 639 THEN 1 ELSE 0 END) AS FICO_620_639,
           SUM(CASE WHEN LNFICO BETWEEN 640 AND 659 THEN 1 ELSE 0 END) AS FICO_640_659,
           SUM(CASE WHEN LNFICO BETWEEN 660 AND 679 THEN 1 ELSE 0 END) AS FICO_660_679
    FROM tbl

RUN;

答案 1 :(得分:0)

我希望你不是这样做的,因为这不是一种合适的聚合方法。

那就是说,如果有正当理由去做你正在做的事情,你可以通过自我更新的方式将它们结合起来。这会将行折叠为一个。

  this.http.post(
            bcs_config.api_url+'/partner/scheduling/srfsearchbycustomer?customerId='+arg+'&timeZoneId='+arg1+
            '&startDate='+arg2+'&endDate='+arg3+'&meetsStatus='+arg4,null,
            config).success(SuccessCallback).error(ErrorCallback);