计算百分比和分数
Calculating percentages and scores
假设我有如下数据:
ID A1Q A2Q B1Q B2Q Continued
23 1 2 2 3
24 1 2 3 3
为了理解 table 它转化为,ID 为 23 的人对问题 A1、A2、B1、B2 的答案分别为 1、2、2、4。我想知道如何知道在整个数据集中回答 1、2 或 3 的学生的百分比。
我试过使用
PROC FREQ data = test.one;
tables A2Q-A2Q;
tables B1Q-B2Q;
RUN;
但这并没有让我得到我想要的。它分别分析每个问题,输出很长。我只需要把它变成一个 table 告诉我这个百分比回答 1,这个百分比回答 2 等等
输出可能是:
Question: 1 2 3
Percentage A1Q 40% 40% 20%
Percentage A2Q 60% 20% 20%
Total Percentage 30% 30% 40%
所以对于问题 A1Q,它会翻译成 40% 的人选择 1,40% 的人选择 2,30% 的人选择 3。总百分比是在所有给出答案的人中,30% 选择 1 30% 选择 2 和 40% 选择 3.
我的建议是转置您的数据,然后进行 proc freq 或 proc tabulate。我会推荐 proc tabulate,这样你就可以格式化你的输出,因为看起来你有分组的问题。
data long;
set have;
array qs(*) a1q--b2q; *list first and last variable and everything in between will be included;
do i=1 to dim(qs);
question=vname(qs(i));
response=qs(i);
output;
end;
keep id question response;
run;
proc freq data=long;
table question*response/list;
run;
您仍然需要对其进行一些处理并转置最终结果,但这可能是一个开始...此外,如果您有很多问题,请考虑将其包含在一个宏程序中。
data quest;
input ID A1Q A2Q B1Q B2Q;
datalines;
21 2 3 1 2
22 3 2 2 3
23 1 2 2 3
24 1 2 3 3
25 2 1 3 3
run;
options missing = 0;
proc freq data=quest;
table A1Q / nocol nocum nofreq out = freq1(rename=(A1Q=Answer Count=A1Q));
table A2Q / nocol nocum nofreq out = freq2;
table B1Q / nocol nocum nofreq out = freq3;
table B2Q / nocol nocum nofreq out = freq4;
run;
proc sql;
create table results as
select freq1.Answer,
freq1.Percent as pctA1Q,
freq2.Percent as pctA2Q,
freq3.Percent as pctB1Q,
freq4.Percent as pctB2Q
from freq1
left join freq2
on freq1.Answer = freq2.A2Q
left join freq3
on freq1.Answer = freq3.B1Q
left join freq4
on freq1.Answer = freq4.B2Q;
quit;
假设我有如下数据:
ID A1Q A2Q B1Q B2Q Continued
23 1 2 2 3
24 1 2 3 3
为了理解 table 它转化为,ID 为 23 的人对问题 A1、A2、B1、B2 的答案分别为 1、2、2、4。我想知道如何知道在整个数据集中回答 1、2 或 3 的学生的百分比。
我试过使用
PROC FREQ data = test.one;
tables A2Q-A2Q;
tables B1Q-B2Q;
RUN;
但这并没有让我得到我想要的。它分别分析每个问题,输出很长。我只需要把它变成一个 table 告诉我这个百分比回答 1,这个百分比回答 2 等等
输出可能是:
Question: 1 2 3
Percentage A1Q 40% 40% 20%
Percentage A2Q 60% 20% 20%
Total Percentage 30% 30% 40%
所以对于问题 A1Q,它会翻译成 40% 的人选择 1,40% 的人选择 2,30% 的人选择 3。总百分比是在所有给出答案的人中,30% 选择 1 30% 选择 2 和 40% 选择 3.
我的建议是转置您的数据,然后进行 proc freq 或 proc tabulate。我会推荐 proc tabulate,这样你就可以格式化你的输出,因为看起来你有分组的问题。
data long;
set have;
array qs(*) a1q--b2q; *list first and last variable and everything in between will be included;
do i=1 to dim(qs);
question=vname(qs(i));
response=qs(i);
output;
end;
keep id question response;
run;
proc freq data=long;
table question*response/list;
run;
您仍然需要对其进行一些处理并转置最终结果,但这可能是一个开始...此外,如果您有很多问题,请考虑将其包含在一个宏程序中。
data quest;
input ID A1Q A2Q B1Q B2Q;
datalines;
21 2 3 1 2
22 3 2 2 3
23 1 2 2 3
24 1 2 3 3
25 2 1 3 3
run;
options missing = 0;
proc freq data=quest;
table A1Q / nocol nocum nofreq out = freq1(rename=(A1Q=Answer Count=A1Q));
table A2Q / nocol nocum nofreq out = freq2;
table B1Q / nocol nocum nofreq out = freq3;
table B2Q / nocol nocum nofreq out = freq4;
run;
proc sql;
create table results as
select freq1.Answer,
freq1.Percent as pctA1Q,
freq2.Percent as pctA2Q,
freq3.Percent as pctB1Q,
freq4.Percent as pctB2Q
from freq1
left join freq2
on freq1.Answer = freq2.A2Q
left join freq3
on freq1.Answer = freq3.B1Q
left join freq4
on freq1.Answer = freq4.B2Q;
quit;