I need to do a frequency distribution of this one column data without using any proc freq; proc sql. I'm only allowed to use proc sort.
In excel I would use a simple countif, but I don't know how to do this in SAS given above contraint.
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;
I came up with this but it stopped counting at 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;
Ultimately I'm looking to a simple table like this: enter image description here