这是我的问题:我有一个数据集,随着时间的推移有10个测量值,如下所示:
ID Expenditure Age
25 100 89
25 102 89
25 178 89
25 290 89
25 200 89
.
.
.
26 100 79
26 102 79
26 178 79
26 290 79
26 200 79
.
.
.
27 100 80
27 102 80
27 178 80
27 290 80
27 200 80
.
.
.
现在我想获得年龄的频率,所以我这样做了:
proc freq data=Expenditure;
table Age / out= Age_freq outexpect sparse;
run;
输出:
Age Frequency Count Percent of total frequency
79 10 0.1
80 140 1.4
89 50 0.5
问题是这会计算所有行,但不会考虑每个ID的重复测量。所以我想用这样的实际频率创建一个新的列:
data Age;
set Age_freq;
freq = Frequency Count /10;
run;
但我认为sas不承认这个'频率计数'变量,有人能给我一些见解吗?
感谢
答案 0 :(得分:2)
您必须删除重复记录,以便每个ID都有一条包含年龄的记录。
解决方案:使用ID和年龄的disticnt值创建一个新表。然后运行proc freq
<强>代码:强> 我创建了一个名为Expenditure_ids的新表,它没有任何重复的ID和ID值。年龄。
data Expenditure;
input ID Expenditure Age ;
datalines;
25 100 89
25 102 89
25 178 89
25 290 89
25 200 89
26 100 79
26 102 79
26 178 79
26 290 79
26 200 79
27 100 80
27 102 80
27 178 80
27 290 80
27 200 80
28 100 80
28 102 80
28 178 80
28 290 80
28 200 80
;
run;
proc sql;
create table Expenditure_ids as
select distinct ID, Age from Expenditure ;
quit;
proc freq data=Expenditure_ids;
table Age / out= Age_freq outexpect sparse;
run;
<强>输出:强>
Age=79 COUNT=1 PERCENT=25
Age=80 COUNT=2 PERCENT=50
Age=89 COUNT=1 PERCENT=25