CARDINALITY Procedure

Example 7.1 Limited Cardinality of the Species Variable

(View the complete code for this example.)

This example illustrates how you can use PROC CARDINALITY to determine the limited cardinality of a variable. It uses the same input data table as is used in the section Getting Started: CARDINALITY Procedure.

You can load the sashelp.iris data set into your SAS session by using the following DATA step:

data mylib.iris;
   set sashelp.iris;
run;

The following statements run PROC CARDINALITY and plot the levels from the details data set for the variable Species:

proc cardinality data=mylib.iris outcard=mylib.card
                 outdetails=mylib.details maxlevels=5;
run;

data sp;
   set mylib.details( where=(_varname_='Species'));
   label _cfmt_='Formatted value of the variable Species';
   if _index_ = . then do;
      _cfmt_=cats(">",left(_cfmt_));
   end;
  _cfmt_=left(_cfmt_);
run;

proc sgplot data=sp;
  vbar _cfmt_ / freq=_freq_;
run;

Output 7.1.1 shows that the variable Species has only three levels in the details data.

Output 7.1.1: Histogram of Species

 Histogram of Species


Whether MAXLEVELS=100 or 5, the Species variable remains fully visible with a _CARDINALITY_ value of 3.

Last updated: May 14, 2026