SAS Proc SQL Count问题

时间:2013-07-17 19:43:04

标签: sas proc-sql

我有一列数据,列名为(Daily_Mileage)。我有15种不同类型的每日里程和250行。我希望每15个里程数分别计算一次。我在SAS中使用PROC SQL,它不喜欢Cross join命令。我不确定我应该做什么,但这就是我的开始:

PROC SQL;
select A, B
From (select count(Daily_Mileage) as A from Work.full where Daily_Mileage = 'Farm Utility Vehicle (Class 7)') a
cross join (select count(Daily_Mileage) as B from Work.full where Daily_Mileage = 'Farm Truck Light (Class 35)') b);
QUIT;

3 个答案:

答案 0 :(得分:2)

使用案例陈述来定义您的计数如下。

proc sql;
  create table submit as
  select sum(case when Daily_Mileage = 'Farm Utility Vehicle (Class 7)'
                  then 1 else 0 end) as A,
         sum(case when Daily_Mileage = 'Farm Truck Light (Class 35)'
                  then 1 else 0 end) as B
  from Work.full
  ;
quit ;

答案 1 :(得分:1)

你不能只使用proc freq吗?

data example ;
  input @1 Daily_Mileages $5. ;
datalines ;
TYPE1
TYPE1
TYPE2
TYPE3
TYPE3
TYPE3
TYPE3
;
run ;

proc freq data = example ;
  table Daily_Mileages ;
run ;

/* Create an output dataset */    
proc freq data = example ;
  table Daily_Mileages /out=f_example ;
run ;

答案 2 :(得分:0)

您可以先创建另一列1,然后对该列和GROUP BY Daily_Mileage进行SUM。如果我误解了你的问题,请告诉我。

PROC SQL;
   CREATE TABLE tab1 AS
   SELECT Daily_Mileage, 1 AS Count, SUM(Count) AS Sum
   FROM <Whatever table your data is in>
       GROUP BY Daily_Mileage;
QUIT;