我有这个问题,但是在 SAS 中。要使用此问题中提供的示例,我有 5 列名称(name_1、name_2 等),并希望输出一个列表,其中名称按频率降序排列:
John 502
Robert 388
William 387
...
... 1
我回答了上面提到的问题,并用“proc sql;”包围了它。和“退出;”:
proc sql;
create table freqs as
SELECT name, COUNT(1)
FROM ( SELECT name_1 AS name FROM mytable
UNION ALL SELECT name_2 AS name FROM mytable
UNION ALL SELECT name_3 AS name FROM mytable
UNION ALL SELECT name_4 AS name FROM mytable
UNION ALL SELECT name_5 AS name FROM mytable
) AS myunion
GROUP BY name
ORDER BY COUNT(1) DESC
;
quit;
但我得到:
ERROR: Summary functions are restricted to the SELECT and HAVING clauses only.
我正在使用 SAS 9.2。
想法?谢谢您的帮助!