SPARSEML Procedure

Example 32.1 Sparse Data Set Example

This example uses the SPARSEML procedure to train a model by using the same data set, smldata, as in the section Getting Started: SPARSEML Procedure. Here, you can add a column id to the smldata data set to serve as the ID variable, as shown in the following statements:

data smldata;
    id = _N_;
    set smldata;
run;

You can load the smldata data set into your SAS library in the following DATA step:

data mylib.smldata;
    set smldata;
run;

The following statements use PROC SPARSEML to run the sparse machine learning algorithm on the mylib.smldata data table and generate the analytic store mylib.mystate:

proc sparseml data= mylib.smldata
    TOLERANCE=0.01
    C = 5.5
    MAXITERS=10
    ;
    input vars;
    savestate rstore=mylib.mystate;
    output out=mylib.trainingout copyvars=(id);
run;

The PROC SPARSEML statement has options such as TOLERANCE=, C=, and MAXITERS=. The INPUT statement defines the input variable vars, which includes both target and sparse input values. The SAVESTATE statement specifies the remote data table mylib.mystate, where the analytic store is saved. The OUTPUT statement shows that the training output table is mylib.trainingout, which includes the variable id.

PROC SPARSEML generates several ODS tables, some of which are shown in Output 32.1.1 through Output 32.1.3.

The "Data Information" table in Output 32.1.1 shows that the number of observations is 15, the number of features is 2, and the number of sparse elements is 26.

Output 32.1.1: Sparse Data Information

The SPARSEML Procedure

Data Information
Number of Rows15
Number of Features2
Number of Sparse Elements26


The "Misclassification Matrix" table in Output 32.1.2 shows that among the total of fifteen observations, nine observations are classified as 1, and six observations are classified as –1. The number of correctly predicted 1 observations is four, and the number of correctly predicted –1 observations is six. Thus the accuracy is 66.67%, as indicated in the "Fit Statistics" table in Output 32.1.3.

Output 32.1.2: Misclassification Matrix

Misclassification Matrix
ObservedTraining Prediction
1-1Total
1459
-1066
Total41115


Output 32.1.3: Fit Statistics

Fit Statistics
StatisticTraining
Accuracy0.6667
Error0.3333
Sensitivity0.4444
Specificity1.0000


The generated analytic store mylib.mystate can be used by PROC ASTORE to score data. For example, you can score the mylib.smldata data table as follows:

proc astore;
    score data=mylib.smldata
       out=mylib.smlscore
       rstore=mylib.mystate
       copyvars=(id)
       ;
    run;
quit;

The score output data are saved in the mylib.smlscore data table.

Last updated: September 23, 2026