Example: Discriminant Analysis on Crops Data

To create this example:
  1. In SAS Studio, click New Options Icon and select New SAS Program.
  2. Create the Crops data set by copying and pasting this code into a Program tab.
    data crops;
       length crop $ 10;
       input Crop x1-x4 ;
       datalines;
    Corn       16 27 31 33
    Corn       15 23 30 30
    Corn       16 27 27 26
    Corn       18 20 25 23
    Corn       15 15 31 32
    Corn       15 32 32 15
    Corn       12 15 16 73
    Soybeans   20 23 23 25
    Soybeans   24 24 25 32
    Soybeans   21 25 23 24
    Soybeans   27 45 24 12
    Soybeans   12 13 15 42
    Soybeans   22 32 31 43
    Cotton     31 32 33 34
    Cotton     29 24 26 28
    Cotton     34 32 28 45
    Cotton     26 25 23 24
    Cotton     53 48 75 26
    Cotton     34 35 25 78
    Sugarbeets 22 23 25 42
    Sugarbeets 25 25 24 26
    Sugarbeets 34 25 16 52
    Sugarbeets 54 23 21 54
    Sugarbeets 25 43 32 15
    Sugarbeets 26 54  2 54
    Clover     12 45 32 54
    Clover     24 58 25 34
    Clover     87 54 61 21
    Clover     51 31 31 16
    Clover     96 48 54 62
    Clover     31 31 11 11
    Clover     56 13 13 71
    Clover     32 13 27 32
    Clover     36 26 54 32
    Clover     53 08 06 54
    Clover     32 32 62 16
    run;
    Click Submit SAS Code Icon to create this data set in the Work library.
  3. In the Tasks section, expand the Multivariate Analysis folder, and then double-click Discriminant Analysis. The user interface for the Discriminant Analysis task opens.
  4. On the Data tab, select the WORK.CROPS data set.
    Tip
    If the data set is not available from the drop-down list, click Select a table icon. In the Choose a Table window, expand the library that contains the data set that you want to use. Select the data set for the example and click OK. The selected data set should now appear in the drop-down list.
  5. Assign columns to these roles:
    Role
    Column Name
    Group variable
    Crop
    Quantitative variables
    x1
    x2
    x3
    x4
  6. To run the task, click Submit SAS Code.
Here is a subset of the results:
Results from Discriminant Analysis Task
Generalized Squared Distance to Crop