I have the dataset as below:
Student Group Class Grade
001 7 2 A
002 7 1 B
003 5 3 A
004 5 4 C
005 6 2 B
I want to use proc freq to get total count for each group according to each grade, also for each class under each group. And proc transpose to get the final dataset will look like as below: (n is the count for each class, N is the count for each Group)
Group Grade
class A B C
7 N N N
1 n n n
2 n n n
5 N N N
3 n n n
4 n n n
6 N N N
1 n n n
2 n n n
This report layout is done far more simply by PROC TABULATE. No transposing required:
proc tabulate data=have order=data noseps;
class group class grade;
table group*class,grade * F=comma6.0;
run;
Primary documentation at Tabulate Procedure
Do you want a data set or a report (people read these)?
Proc freq will generate the counts you want but not display it that way.
Here is where I would start:
proc tabulate data=have; class group class grade; table group*(all=' ' class=' '), grade*n=' ' /misstext=' ' ; run;
The =' ' are suppressing default text. This procedure defaults to repeating sub-group headings (your Class variable). The All provides a summary line. Done this way with the parentheses with it and Class it will be summary of the all of the Class variable counts. The order of appearance of values, such as the Group variable will normally be in formatted value order. You did not specify if the order was critical. There are several ways to force orders but depend on having a more complete data set and may involving SORTing the data or creating helper formats combined with options.
I would need a dataset.
@JillChen0131 wrote:
I would need a dataset.
How will you use a data set?
The structure you are showing with a group in one column and not repeating, then a blank for the total row in grade is going to be extremely difficult to use for any purpose I can think of.
Proc Tabulate will create an output data set, it just won't look like that because of the flexibility of creating many more nestings of rows and column headings.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.