不使用proc的SAS countif函数

不使用proc的SAS countif函数,sas,countif,frequency-distribution,Sas,Countif,Frequency Distribution,我需要在不使用任何proc freq的情况下对这一列数据进行频率分布;procsql。我只允许使用proc sort 在excel中,我会使用一个简单的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; 我想出了这个,但一点也不算- data new_dataset; set Fal

我需要在不使用任何proc freq的情况下对这一列数据进行频率分布;procsql。我只允许使用proc sort

在excel中,我会使用一个简单的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;
我想出了这个,但一点也不算-

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;
最终,我希望看到这样一个简单的表格:

将数据步骤视为循环是有帮助的,循环在输入数据集中运行,并在运行时拾取值。我本想解释一下你在这方面的努力是如何起作用的,但很快就让人困惑了。下面是我对这个问题的尝试:

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;
首先按等级对数据进行排序,以便进行分组处理:

proc sort data=sample_grades;
  by grades;
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;