Search code examples
sasenterprise-guide

Adding percent % to the proc tabulate report


I have a proc tabulate code as below:

  proc tabulate data=want;
class TERM CAMPUS GENDER ;
  var count ;
 table  GENDER ALL, (CAMPUS all)*TERM*(count='#Enrl '*f=best8.*sum=' ' count=''*colpctsum='% Tot Enrl ' ) / rts=20;
run;

and my result is as below

                               campus
                             East Campus
                               Term
           Spring 2014               Spring 2015             Dfference
        #Enrl     %Tot_Enrl         #Enrl   %ToT_Enrl      #Enrl   %Tot_Enrl
Gender   
Female   8462      52.86             8429    52.36          -33       -37.08
Male     7478      46.71             7608    47.26          130       146.07
None     68        0.42              60      0.37            -8        -8.89
All      16008      100.00           16907    100.00        89          100

I need to add % sign in the '%Tot_Enrl' variables. Also can i remove campus and term titles? I have 'campus' title and 'east campus' title. So i need to remove 'Campus' and 'Term'. is that possible?


Solution

  • You need some more =' ' to get rid of Campus and Term. To get percent sign, you need a format; SAS shows you how here.

    data want;
      format term $15. campus $15.;
      input term $ & campus $ & gender $ count;
      datalines;
    Spring 2014  East Campus  Female 8462
    Spring 2014  East Campus  Male 7478
    Spring 2014  East Campus  None 68
    Spring 2015  East Campus  Female 8429
    Spring 2015  East Campus  Male 7608
    Spring 2015  East Campus  None 60
    Difference  East Campus  Female -33
    Difference  East Campus  Male 130
    Difference  East Campus  None -8
    ;;;;
    run;
    
    
    
    proc format;                           
       picture mypct(round) low-high='000,009.90%' (mult=100);   
    run; 
    
    
    proc tabulate data=want;
      class TERM CAMPUS GENDER ;
      var count ;
      table  GENDER ALL, (CAMPUS=' ' all)*TERM=' '*(count='#Enrl '*f=best8.*sum=' ' count=''*colpctsum='% Tot Enrl '*f=mypct. ) / rts=20;
    run;
    

    The sorting ends up wrong, I'm guessing you have a formatted numeric for some of that, but it gets the idea across.