/**********************************************************************/


   /* Appendix */

   /* The following OPTIONS statement is used with the programs */
   /* in this appendix:                                         */
options ls=80 ps=60;                                             


/**********************************************************************/


   /* Code for Output 1: Simple PCTN Example                    */
proc tabulate data=employee;                             
   class location dept sex;                              
   table location*dept,sex*(n*f=5.0 pctn*f=6.2) / rts=25;
   title;                                                
run;                                                     


/**********************************************************************/


   /* Code for Output 2: Simple PCTSUM Example                  */                                                  
proc tabulate data=employee;                             
   class location dept sex;                              
   var income;                                           
   table location*dept,sex*income=' '*(sum*f=dollar11.2 
         pctsum='PCT-SUM' *f=5.2) / rts=22;                 
run;                                                     


/**********************************************************************/


   /* Code for Output 3: Calculating Row Percentages            */
proc tabulate data=employee;                             
   class dept sex;                                       
   table dept,(sex all)*(n*f=5.0 pctn*f=7.2)   
         / rts=13;                                       
   keylabel all='Row Totals' n='Count' pctn='Row Percent';
run;                                                      


/**********************************************************************/


   /* Code for Output 4: Calculating Column Percentages         */
proc tabulate data=employee;                                  
   class location dept sex;                                   
   table location*dept all,                                   
         sex*(n*f=7.0 pctn*f=7.2) / rts=23;
   keylabel all='Column Totals' n='Count'                     
            pctn='Column  Percent';                           
run;                                                          


/**********************************************************************/


  /* Code for Output 5: Calculating Percentages of Page Totals  */
proc tabulate data=employee;                          
   class location dept sex;                           
   table location,dept all='Column Totals',           
         (sex all='Row Totals')*                      
         (n*f=5.0 pctn*f=7.2)
         / rts=13;                                 
   keylabel n='Count' pctn='Page  Percent';           
run;                                                  


/**********************************************************************/


   /* Code for Output 6: Calculating Percentages for            */
   /* Concatenated Tables                                       */
proc tabulate data=employee;                     
   class location dept sex;                      
   table location dept,                          
         sex*(n*f=5.0 pctn*f=7.2) 
         / rts=13;                           
   keylabel n='Count' pctn='Percent of this Sex';
run;                                             


/**********************************************************************/


   /* Code for Output 7: Concatenating the ALL Variable         */
   /* in an Expression                                          */
proc tabulate data=employee;                        
   class location dept sex;                         
   table location dept all='Total for Each Sex',    
         sex*(n*f=5.0 pctn*f=7.2)
         / rts=20;                                  
   keylabel n='Count' pctn='Percent of this Sex';   
run;                                                


/**********************************************************************/


   /* Code for Output 8: The Significance of Ordering           */
   /* in Concatenated Expressions                               */
proc tabulate data=employee;                           
   class dept month;                                   
   table all='All Departments' dept,                   
         (all='Year-to-Date' month)*(n*f=5.0           
         pctn*f=7.2) / rts=13               
         box='Table 1:  Row % defined with ALL first'; 
   table all='All Departments' dept,                   
         (all='Year-to-Date' month)*(n*f=5.0           
         pctn*f=7.2) / rts=13                
         box='Table 2:  Row % defined with MONTH first';
   keylabel n='Count' pctn='Row Percent';              
run;                                                   


/**********************************************************************/


   /* Code for Output 9: Frequencies of Men and Women           */
   /* in the Monthly Work Force for Each Department at          */
   /* the Two Plant Locations                                   */
proc tabulate data=employee;                    
   class location dept month sex;               
   table location*(dept all='All Depts.'),      
         month*(sex*f=4.0 all='Both Sexes'*f=5.0)*n
         / rts=22;                                  
   keylabel n='#';                              
run;                                                               


/**********************************************************************/


   /* Code for Output 10: Percentages Based on Sex and          */
   /* Department Subtotals                                      */
proc tabulate data=employee;                        
   class location dept month sex;                   
   table location*(dept all='All Depts.'),          
         month*(sex*f=5.2 all='Both Sexes'*f=6.2)*  
         pctn / rts=2
         box='Percent of SEX/DEPT Subtotal';        
   keylabel pctn=' ';                               
run;                                                


/**********************************************************************/


   /* Code for Output 11: Using an Analysis Variable            */
   /* as a Denominator                                          */
proc tabulate data=employee;                        
   class dept month;                                
   var income tottax;                               
   table dept, month*                               
         (income='Wages Expended'*sum*f=comma8.0    
         tottax='Total Tax Withheld'*sum*f=comma8.0 
         tottax='% of Wages Taken for Taxes'        
         *pctsum*f=5.1)                     
         / rts=12;                                  
   keylabel sum=' ' pctsum=' ';                     
run;                                                


/**********************************************************************/


   /* Code for Output 12: Percentage of Male Income             */
   /* to Female Income                                          */
data ratio;                                            
   set employee;                                       
   if sex='M' then male=income;                        
      else if sex='F' then female=income;              
run;                                                   

proc tabulate data=ratio;                              
   class dept;                                         
   var male female;                                    
   table dept,male*sum*f=dollar12.2                   
         female*sum*f=dollar12.2                             
         male=' '*pctsum*f=12.2 / rts=13;      
   keylabel sum='Income'                               
            pctsum='Male Income as % of Female Income';
run;                                                   


/**********************************************************************/


   /* Code for Output 13: Percentage of Male Income             */
   /* to Female Income Displayed as a Ratio                     */                                   
proc format;                                            
   picture ratiofmt other='09.99' (mult=1 prefix='1:');
run;                                                    

proc tabulate data=ratio;                               
   class dept;                                          
   var male female;                                        
   table dept,male*sum*f=dollar12.2                       
         female*sum*f=dollar12.2                                 
         male=' '*pctsum*f=ratiofmt8. / rts=13;    
   keylabel sum='Income'                                   
            pctsum='Ratio of Male Income to Female Income';
run;                                                       


/**********************************************************************/


   /* Code for Output 14: Computing a Customized Mean           */
data mean;                                                 
   set employee;                                           
   count=1;                                                

proc format;                                               
   picture meanfmt other='0009.99' (mult=1);              

proc tabulate data=mean;                                   
   class dept;                                             
   var income count;                                       
   table dept,income='Wages Expended'*sum*f=comma10.2     
         income='Obser-vations with Nonmissing INCOME'*n*f=10.
         income='Mean Computed by TABULATE'*mean*f=8.2        
         count='Total Number of  Obser-vations'*sum*f=7.      
         income='"Mean" Computed with PCTSUM'*                
         pctsum*f=meanfmt8.                                      
         / rts=12;                               
   keylabel n=' ' sum=' ' pctsum=' ' mean=' ';
run;                                          


/**********************************************************************/


   /* Code for Output 15: Specifying a Constant Value           */
   /* as the Denominator                                        */
data constant;                                  
   set employee;                                
   if _n_=1 then denom=400;                     
run;                                            

proc tabulate data=constant;                    
   class dept sex;                              
   var income denom;                            
   table dept,sex*income=' '*                  
         (sum='Total Wages Expended'*f=comma10.2
         pctsum=                
         'Wages Expended per Pay Period'*f=comma9.2) 
         / rts=12;                  
run;                                            


/**********************************************************************/