2017-05-09 11 views
0

proc freqを使用せずにこの1つの列データの頻度分布を行う必要があります。 proc sql。私はprocソートしか使用できません。procを使用しないでSAS countif関数

私は単純なcountifを使用しますが、上記の制約を受けてSASでこれを行う方法はわかりません。

data sample_grades; 
input grades $; 
datalines; 
C 
A 
A 
B 
B+ 
A- 
W 
A 
A- 
A 
A- 
A 
B+ 
A- 
A 
B+ 
B+ 
A- 
B+ 
; 
run; 

私はこれを思い付いたが、それは最終的に私はこのような単純な表に探していA-

data new_dataset; 
set Fall2016; 
by grade; 
retain grade frequency; 
if grade = 'A' then frequency+1; 
else if grade = 'A-' then frequency=0; 
if grade = 'A-' then frequency+1; 
else if grade = 'B' then frequency=0; 
if grade = 'B' then frequency+1; 
else if grade = 'B+' then frequency=0; 
if grade = 'B+' then frequency+1; 
else if grade = 'B-' then frequency=0; 
if grade = 'B-' then frequency+1; 
else if grade = 'C' then frequency=0; 
if grade = 'C' then frequency+1; 
else if grade = 'W' then frequency=0; 
if grade = 'W' then frequency+1; 
else frequency+0; 
if last.grade then do; 
frequency+0; 
end; 
run; 

でカウントを停止: enter image description here

答えて

1

それはデータを考えるのに役立ちますループとしてのステップ、入力データセットを実行して行くときに値を取得する。私はその点であなたの試みがどのように機能したのか説明しようとしていましたが、すぐに混乱しました。次のように今、あなたのデータのステップを設定

proc sort data=sample_grades; 
    by grades; 
run; 

:BY-GROUP処理を行うことができるように

data sample_grades; 
input grades $; 
datalines; 
C 
A 
A 
B 
B+ 
A- 
W 
A 
A- 
A 
A- 
A 
B+ 
A- 
A 
B+ 
B+ 
A- 
B+ 
; 
run; 

分類、等級によるデータ最初に:ここでの問題で私の試みです

data new_dataset; 
    set sample_grades; 
    by grades; 
    /* If it's the first of the grades then set the frequency to zero */ 
    if first.grades then frequency=0; 
    /* Increment the frequency value regardless of the value of grades */ 
    frequency+1; 
    /* When the last of the grades values is found, output. This gives the total frequency for the grade in the output table */ 
    if last.grades then output; 
run; 
関連する問題