Sample 25119: How to count the unique instances of a GROUP or ORDER variable with PROC REPORT
The N statistic is helpful to represent the number of observations in a group, but it is often the case that the number of unique instances for a variable are required. This sample code illustrates how to create this count.
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.
This sample uses a COMPUTE block to create a variable called COUNT that contains the unique instances of the variable COLOR.
data example;
input color $ cost;
datalines;
purple 100
purple 200
purple 300
green 120
green 400
green 900
green 135
yellow 555
yellow 1
;
run;
ods listing;
title 'Number of groups';
proc report nowd data=example headskip;
col color n cost;
define color / group 'Color of the day';
define n / 'Colors per group';
define cost / 'Total cost per color';
compute before color;
count+1;
endcomp;
compute after;
line ' ';
line 'Unique number of COLOR values' count 3.;
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.
Number of groups
Color Total
of the Colors cost per
day per group color
green 4 1555
purple 3 600
yellow 2 556
Unique number of COLOR values 3
This sample illustrates how to obtain a frequency count for the unique number of values in a GROUP or ORDER variable.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> REPORT
|
| Date Modified: | 2010-02-03 10:09:26 |
| Date Created: | 2005-01-27 12:18:37 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |