PROC Tabulate!!!!



                     PROC TABULATE is an underused, under appreciated procedure that can create a wide
variety of tabular reports, displaying frequencies, percentages, and descriptive statistics such as sums and means) broken down by one or more CLASS variables. There are several excellent books devoted to PROC TABULATE. This posts introduces you to this procedure and, we hope, piques your interest.

#Problem:
                    Using the college data set which was given in my previous post, we should tabulate using the Proc Tabulate procedure.

#Solution:

title "Demographics from COLLEGE Data Set";
proc tabulate data=A15028.A28_college format=6.;
class Gender Scholarship SchoolSize;
tables SchoolSize all,
Gender Scholarship all/ rts=15;
keylabel n=' '
all = 'Total';
run;

#Output::


#Explanation:

                PROC TABULATE uses a CLASS statement to allow you to specify variables that
represent categories (often character variables) where you want to compute frequencies
or percentages. So here we want to broke down the data based on the school size and type and Gender as well. Next, the TABLE statement specifies the table’s appearance. Any variable listed in a TABLE statement must be listed in a CLASS statement.

                Apart from the above two keywords, we used format option which helps to display in the specific format for every cell in the table. Unlike many other SAS procedures, there are some reserved keywords used by PROC TABULATE and one such keyword is ALL. When you place ALL after a variable name in a table request, PROC TABULATE includes a column representing all levels of the preceding variable. Another customization option is RTS=, which increases the row title space (the space for the width of the row title, including the vertical lines).

              Let us look another example where we can change the names of the variables in the Proc Tabulate Procedure.

#Solution:

title "Descriptive Statistics";
proc tabulate data=A15028.A28_college format=6.1;
class Gender;
var GPA;
tables GPA*(n*f=4.
mean min max),
Gender all;
keylabel n = 'Number'
all = 'Total'
mean = 'Average'
min = 'Minimum'
max = 'Maximum';
run;

#Output:

'
                    In the above output we can see that, the variable name "n" is changed as Number,"min" is changed as "Minimum" and similarly for max and avg. Thus usiing Proc Tabulate we can alter the table based on our needs to report the output.



No comments:

Post a Comment