[英]Frequencies not adding up (SAS PROC SQL)
我正在嘗試僅查找唯一ID號的頻率。 我嘗試了PROC FREQ,但是無論如何選擇SELECT DISTINCT的SAS都無法搞清楚。 我運行了以下代碼,並得到了不會累加的數字。
代碼: PROC SQL; SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n;
PROC SQL; SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n;
結果:20599
碼:
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '1a (obs): Demonstrating knowledge of content and pedagogy';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '1a (p&p): Demonstrating knowledge of content and pedagogy';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '1e (obs): Designing coherent instruction';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '1e (p&p): Designing coherent instruction';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '2a: Creating an environment of respect and rapport';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '2d: Managing student behavior';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '3b: Using questioning and discussion techniques';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '3c: Engaging students in learning';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '3d: Using assessment in instruction';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '4e (obs): Growing and developing professionally';
PROC SQL;
SELECT COUNT (DISTINCT MOTPID) FROM WORK.'0__1_MOTP_COMMENTS_0000'n
WHERE MOTPComponentDescription = '4e (p&p): Growing and developing professionally';
在此處查看數據集的摘要: https : //docs.google.com/spreadsheets/d/1WDcsezb4xiT67J9t3Nlyi_QEofs0dhyZ23yC32ccbqg/edit?usp=sharing
結果:1a(肥胖):展示內容和教學知識:700
1a(p&p):展示內容知識和教學法:606
1e(obs):設計連貫指令:15622
1e(p&p):設計連貫指令:1135
2a:營造尊重和融洽的環境:2466
2d:管理學生行為:1005
3b:使用提問和討論技術:808
3c:讓學生參與學習:2516
3d:在指令中使用評估:3058
4e(obs):專業成長與發展:5245
4e(p&p):專業發展與發展:588
總和= 33746
33746!= 20599
尋找關於出問題的任何想法,或者是否有更好的方法來獲得我想要的結果(MOTPCopmponentDescription對唯一MOTPID的計數。在此先感謝!
為了討論StackOverflow上的SAS問題,SASHELP庫中的示例數據非常方便。 讓我們使用CARS數據集。 ;
標題“您認為有問題的沒問題”;
title2“計算所有品牌”;
proc sql;
select count (distinct Make) as distinct_makes from sashelp.cars;
quit;
title2“計算生產具有一定數量氣缸的汽車的品牌”;
proc sql;
select 'n.a.' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = . union
select ' 3 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 3 union
select ' 4 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 4 union
select ' 5 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 5 union
select ' 6 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 6 union
select ' 8 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 8 union
select '10 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 10 union
select '12 ' as Cylinders, count (distinct Make) as distinct_makes from sashelp.cars where Cylinders = 12;
quit;
title2“您可以手動驗證這些清單中的結果”;
proc sql;
select Cylinders, Make, Model from sashelp.cars order by Cylinders, Make;
select Make, Cylinders, Model from sashelp.cars order by Make, Cylinders;
quit;
標題“您所說的解決方案正在產生不可預測的結果”;
title2“如果以一種方式對輸入進行排序,則會產生此結果”;
proc sort data=sashelp.cars out=cars_short2long;
by length;
run;
proc sort data=cars_short2long nodupkey out=cars_short2long_clean dupout=dups;
by Make;
run;
proc freq data=cars_short2long_clean;
table Cylinders;
run;
title2“如果以其他方式對輸入進行排序,則將產生此結果”;
proc sort data=sashelp.cars out=cars_long2short;
by descending length;
run;
proc sort data=cars_long2short nodupkey out=cars_long2short_clean dupout=dups;
by Make;
run;
proc freq data=cars_long2short_clean;
table Cylinders;
run;
這是我制定的解決方案,得到了我一直在尋找的確切結果:
data comment_analysis;
set WORK.'0__1_MOTP_COMMENTS_0001'n;
run;
proc sort data=comment_analysis nodupkey out=comment_analysis_clean dupout=dups;
by motpid;
run;
proc freq data=comment_analysis_clean;
table MOTPComponentDescription;
run;
這是我在尋找的輸出:MOTPComponentDescription Frequency Percent
1a(肥胖):展示內容和教學法知識520 2.52%
1a(p&p):展示內容和教學法知識400 1.94%
1e(obs):設計連貫指令11423 55.45%
1e(p&p):設計連貫指令526 2.55%
2a:營造尊重和融洽的環境1629 7.91%
2d:管理學生行為556 2.70%
3b:使用提問和討論技巧563 2.73%
3c:吸引學生學習1593 7.73%
3d:在指令1818中使用評估8.83%
4e(obs):專業發展1235 6%
4e(p&p):專業成長與發展336 1.64%
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.