In SAS, how to conditionally collapse rows, substituting with an explicitly name single row representing sum of values?
Specifically, I am looking to create a frequency table that displays the frequencies of value Subclass, but on the condition that that frequency is >9. In any other case (frequency <10), I want the frequency to count towards a sum of frequencies restricted to value Class. There are no missing or 0 values in the dataset.
Freq Class Subclass
---------------------
20 1 1a
20 1 1b
2 1 1c
2 1 1d
2 1 1e
1 1 1f
22 2 2a
6 2 2b
2 2 2c
1 2 2d
31 3 3a
17 3 3b
7 3 3c
3 3 3d
3 3 3e
My current approach has produced the first table using:
proc sql;
create table as
select* count (distinct subjectID) as count
from DATASET1
group by Subclass
;
run; quit;
The desired result would look something like this:
Freq Class Subclass
---------------------
20 1 1a
20 1 1b
7 1 OTHER (1c, 1d, 1e, 1f)
22 2 2a
9 2 OTHER (2b, 2c, 2d)
31 3 3a
17 3 3b
13 3 OTHER (3c, 3d, 3e)
Preferably I would like to additionally explicitly name the Subclass value representing the the summed measurement according to identifiers of the measurements represented in the rows. In this example that would be the names of the subclasses summed up.
I have tried using the Proc means
procedure, which yields a new dataset of all Subclasses
with frequency <10, rather than a sum value.