你的代碼是給內部COUNT(*)結果的標籤,但它沒有給他們一個變量名稱。
SAS PROC SQL可以讓你寫的代碼,你不給你的變量名,只是在做一個選擇,甚至做當SELECT *時。
select count(*) "Total number of rows" from sashelp.class ;
select * from
(select count(*) "Label 1" from sashelp.class
union all
select count(*) "Label 2" from sashelp.class
)
;
你甚至可以用它們來製作數據集,在這種情況下,SAS會生成一個變量名。試試這個:
create table test1 as
(select count(*) "Total number of rows" from sashelp.class)
;
describe table test1 ;
但是如果你想使用的變量像SUM()
表達式,那麼你必須給變量的名稱,而不是隻是一個標籤。否則,你不知道該把什麼放在聚合函數調用中。一般來說,給出你的派生變量名是個好主意。
select sum(counts) as total_count label="Total of count(*)" from
(select count(*) as counts from sashelp.class
union all
select count(*) as counts from sashelp.class
)
;
你可以嘗試DQUOTE=ANSI
選項添加到您的PROC SQL
聲明。這會將"name"
視爲變量名而不是字符串。但是您仍然需要在名稱前添加AS
關鍵字。
proc sql dquote=ansi;
select sum(counts)
from (
select count(*) as "counts" from sashelp.class
union
select count(*) as "counts" from sashelp.class
)
;
quit;
來源
2017-03-07 22:40:58
Tom
我想那些是兩個不同的錯誤?你需要一個別名爲你的列, –