BookmarkSubscribeRSS Feed
JillChen0131
Fluorite | Level 6

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

4 REPLIES 4
mkeintz
PROC Star

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 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

 

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.

JillChen0131
Fluorite | Level 6

I would need a dataset.

ballardw
Super User

@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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 683 views
  • 2 likes
  • 3 in conversation