【问题标题】:Using proc freq with repeated ID variables使用带有重复 ID 变量的 proc freq
【发布时间】:2016-04-12 22:42:43
【问题描述】:

我想使用 proq freq 来计算某人在特定日期食用的食物类型的数量(fint 变量)。我的数据是长格式的,针对不同的食物类型和不同的采访日期重复了 idno。但是 SAS 挂起并且不运行代码。我有超过 300,000 条数据线。还有其他方法吗?

proc freq;  
  tables idno*fint*foodtype / out=countft;  
run;

【问题讨论】:

  • 30 万条记录是微不足道的。还有别的问题。可能组合太多?您期望有多少种不同的组合?具有不同计数的 proc sql 是否有效?
  • 您的 proc freq 中的 data= 语句在哪里?您确定它指向正确的数据集吗?
  • 谢谢 Reeza..我只是缩写,所以数据步骤很好。我认为我的组合太多了。

标签: sas frequency proc


【解决方案1】:

我有点不确定你的数据结构,但是proc的意思也可以数。 假设每个人有多个日期,每个日期有多个食物类型,您可以使用:

data dataset;
set dataset;
count=1;
run;
proc means data=dataset sum;
class idno fint foodtype;
var count;
output out=countft sum=counftpday;
run;

/* Usually you only want the lines with the largest _type_, so keep going here */

proc sql noprint;
select max(_type_) into :want from countft;
quit;  /*This grabs the max _type_ from output file */

data countft;
set countft;
where _type_=&want.;
run;

【讨论】:

  • 你可以在proc上使用NWAY选项来自动保持最大的type
【解决方案2】:

试试 proc sql:

proc sql;
create table want as
select distinct idno, fint, foodtype, count(*) as count
from have
order by 1, 2, 3;
quit;

更糟糕的情况,在数据步骤中排序和计数。

proc sort data=have; 
by idno fint foodtype;
run;

data count;
set have;
by idno fint foodtype;
if first.foodtype then count=1;
else count+1;
if last.foodtype then output;
run;

【讨论】:

    猜你喜欢
    • 2018-01-03
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多