![]()  | ![]()  | ![]()  | ![]()  | ![]()  | 
The sample code on the Full Code tab shows how to calculate percentages within groups using PROC REPORT. 
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
The sample code below shows how to calculate percentages within groups using PROC REPORT.  A COMPUTE BEFORE  block is used to assign analysis variables' group total to a DATA step variable.  The percents are then calculated in a separate COMPUTE block, using the DATA step variable as the denominator.  proc report data=sashelp.cars(obs=200) nowd;
   column make type invoice invper msrp msrpper;
   define make / group;
   define type / group;
   define invper / computed format=percent8.1 'Invoice/Percent';
   define msrpper / computed format=percent8.1 'MSRP/Percent';
/* Put the total sum of Type within Make into a DATA step variable */
   compute before make;
      invden = invoice.sum;
      msrpden = msrp.sum;
   endcomp;
/* Compute the percents */
   compute invper;
      if invden > 0 then invper = invoice.sum / invden;
   endcomp;
   compute msrpper;
      if msrpden > 0 then msrpper = msrp.sum / msrpden;
   endcomp;
run;
          These sample files and code examples are provided by SAS Institute
          Inc. "as is" without warranty of any kind, either express or implied, including
          but not limited to the implied warranties of merchantability and fitness for a
          particular purpose. Recipients acknowledge and agree that SAS Institute shall
          not be liable for any damages whatsoever arising out of their use of this material.
          In addition, SAS Institute will provide no support for the materials contained herein.
        
                                      Invoice                MSRP
  Make           Type       Invoice   Percent      MSRP   Percent
  Acura          SUV        $33,337    12.3%    $36,945    12.3%
                 Sedan     $156,821    58.1%   $173,860    57.8%
                 Sports     $79,978    29.6%    $89,765    29.9%
  Audi           Sedan     $486,207    65.1%   $534,400    64.9%
                 Sports    $179,559    24.0%   $198,520    24.1%
                 Wagon      $81,506    10.9%    $89,930    10.9%
  BMW            SUV        $81,593    10.3%    $89,195    10.3%
                 Sedan     $516,085    65.1%   $563,935    65.1%
                 Sports    $164,625    20.8%   $179,730    20.8%
                 Wagon      $30,110     3.8%    $32,845     3.8%
  Buick          SUV        $58,442    23.3%    $64,440    23.4%
                 Sedan     $192,252    76.7%   $210,400    76.6%
  Cadillac       SUV        $91,900    24.7%    $99,790    24.7%
                 Sedan     $160,428    43.2%   $174,830    43.3%
                 Sports     $70,546    19.0%    $76,200    18.9%
                 Truck      $48,541    13.1%    $52,975    13.1%
  Chevrolet      SUV       $120,296    18.5%   $134,750    18.8%
                 Sedan     $282,747    43.5%   $307,300    42.8%
                 Sports     $84,261    13.0%    $96,070    13.4%
                 Truck     $141,944    21.8%   $157,505    21.9%
                 Wagon      $20,394     3.1%    $22,225     3.1%
  Chrysler       Sedan     $318,293    84.0%   $343,055    83.9%
                 Sports     $32,033     8.5%    $34,495     8.4%
                 Wagon      $28,725     7.6%    $31,230     7.6%
  Dodge          SUV        $29,472     9.4%    $32,235     9.4%
                 Sedan     $157,148    50.0%   $169,125    49.6%
                 Sports     $74,451    23.7%    $81,795    24.0%
                 Truck      $53,010    16.9%    $58,145    17.0%
  Ford           SUV       $114,852    22.7%   $128,220    23.2%
                 Sedan     $212,322    42.1%   $229,190    41.5%
                 Sports     $78,301    15.5%    $85,255    15.4%
                 Truck      $62,612    12.4%    $69,935    12.7%
                 Wagon      $36,832     7.3%    $39,765     7.2%
  GMC            SUV       $100,817    47.9%   $113,880    48.2%
                 Sedan      $23,215    11.0%    $25,640    10.8%
                 Truck      $86,283    41.0%    $96,964    41.0%
  Honda          Hybrid     $36,362    11.0%    $39,250    10.8%
                 SUV        $60,596    18.3%    $66,110    18.1%
                 Sedan     $204,794    61.7%   $225,770    62.0%
                 Sports     $29,965     9.0%    $33,260     9.1%
  Hummer         SUV        $45,815   100.0%    $49,995   100.0%
  Hyundai        SUV        $20,201    10.5%    $21,589    10.3%
                 Sedan     $155,122    80.6%   $169,390    80.8%
                 Sports     $17,101     8.9%    $18,739     8.9%
  Infiniti       Sedan     $198,163    75.3%   $217,270    75.3%
                 Wagon      $64,877    24.7%    $71,290    24.7%
  Isuzu          SUV        $49,238   100.0%    $52,298   100.0%
  Jaguar         Sedan     $387,217    65.2%   $424,985    65.2%
                 Sports    $206,738    34.8%   $226,985    34.8%
| Type: | Sample | 
| Date Modified: | 2013-03-20 11:54:48 | 
| Date Created: | 2013-03-11 11:28:35 | 
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | Aster Data nCluster on Linux x64 | ||
| DB2 Universal Database on AIX | ||||
| DB2 Universal Database on Linux x64 | ||||
| Greenplum on Linux x64 | ||||
| Netezza TwinFin 32bit blade | ||||
| Netezza TwinFin 32-bit SMP Hosts | ||||
| Netezza TwinFin 64-bit S-Blades | ||||
| Netezza TwinFin 64-bit SMP Hosts | ||||
| Teradata on Linux | ||||
| z/OS | ||||
| Z64 | ||||
| OpenVMS VAX | ||||
| Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
| Microsoft Windows XP 64-bit Edition | ||||
| Microsoft® Windows® for x64 | ||||
| OS/2 | ||||
| Microsoft Windows 8 Pro | ||||
| Microsoft Windows 95/98 | ||||
| Microsoft Windows 2000 Advanced Server | ||||
| Microsoft Windows 2000 Datacenter Server | ||||
| Microsoft Windows 2000 Server | ||||
| Microsoft Windows 2000 Professional | ||||
| Microsoft Windows NT Workstation | ||||
| Microsoft Windows Server 2003 Datacenter Edition | ||||
| Microsoft Windows Server 2003 Enterprise Edition | ||||
| Microsoft Windows Server 2003 Standard Edition | ||||
| Microsoft Windows Server 2003 for x64 | ||||
| Microsoft Windows Server 2008 | ||||
| Microsoft Windows Server 2008 for x64 | ||||
| Microsoft Windows Server 2012 | ||||
| Microsoft Windows XP Professional | ||||
| Windows 7 Enterprise 32 bit | ||||
| Windows 7 Enterprise x64 | ||||
| Windows 7 Home Premium 32 bit | ||||
| Windows 7 Home Premium x64 | ||||
| Windows 7 Professional 32 bit | ||||
| Windows 7 Professional x64 | ||||
| Windows 7 Ultimate 32 bit | ||||
| Windows 7 Ultimate x64 | ||||
| Windows Millennium Edition (Me) | ||||
| Windows Vista | ||||
| Windows Vista for x64 | ||||
| 64-bit Enabled AIX | ||||
| 64-bit Enabled HP-UX | ||||
| 64-bit Enabled Solaris | ||||
| ABI+ for Intel Architecture | ||||
| AIX | ||||
| HP-UX | ||||
| HP-UX IPF | ||||
| IRIX | ||||
| Linux | ||||
| Linux for x64 | ||||
| Linux on Itanium | ||||
| OpenVMS Alpha | ||||
| OpenVMS on HP Integrity | ||||
| Solaris | ||||
| Solaris for x64 | ||||
| Tru64 UNIX | ||||




