proc sql模式功能

Gab*_*yLP 4 sas

我知道在mysql中没有聚合函数来计算模式(你必须做很多步骤).但我认为在proc sql应该是可能的.有办法吗?代码就像这样:

select phones, mode(state_id)as state from
xxx.listings_abr3 
group by phones
Run Code Online (Sandbox Code Playgroud)

错误是:

无法找到功能模式.

谢谢!

Joe*_*Joe 5

MODE可以proc sql使用子查询.

data have;
  call streaminit(7);
  do id = 1 to 100;
    x = rand('Geometric',.2);
    output;
  end;
run;

proc sql;
 select x as mode from (
        select x, count(1) as count from have group by x
        ) 
    having count=max(count);
quit;
Run Code Online (Sandbox Code Playgroud)

这利用了SAS为您做的自动重新融合; 如果你想避免这种情况,你需要做更多的工作才能让语句工作.

您仍然可能需要对此进行进一步的工作,因为您可能有多种模式,这不区分它们(它返回所有模式).