Synthetic Minority Oversampling Action Set

Using Synthetic Data to Capture the Correlations of Variables in the Original Data

This section contains PROC CAS code.

Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.

This example demonstrates how you can use the smoteSample action to generate synthetic data that preserve the pairwise correlations of variables in the original data.

The following DATA step loads the sashelp.cars data table into your CAS engine. The variables MPG_City, Weight, and EngineSize are three highly correlated variables that are used in this example.

data mycas.cars;
   set sashelp.cars;
run;

This DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

The following statements analyze the correlations among pairs of the three variables in the original data set:

 ods graphics on;
 title "Pearson Correlation and Matrix Plot of Original Data";
 proc corr data=mycas.cars noprob plots=matrix(hist);
    var MPG_City Weight EngineSize;
    ods select PearsonCorr MatrixPlot;
 run;

Output 36.1.1 shows that the Pearson correlation between MPG_City and Weight is –0.73797, between MPG_City and EngineSize is –0.70947, and between Weight and EngineSize is 0.80787.

Output 36.1.1: Pearson Correlation of the Original Data

Pearson Correlation and Matrix Plot of Original Data

The CORR Procedure

Pearson Correlation Coefficients, N = 428
 MPG_CityWeightEngineSize
MPG_City
MPG (City)
1.00000-0.73797-0.70947
Weight
Weight (LBS)
-0.737971.000000.80787
EngineSize
Engine Size (L)
-0.709470.807871.00000


Output 36.1.2 shows the marginal and bivariate distributions of the original data.

Output 36.1.2: Scatter Plot Matrix of the Original Data

Scatter Plot Matrix of the Original Data


The following statements use the smoteSample to apply the synthetic minority oversampling technique (SMOTE) to the cars data table:

 proc cas;
 action smote.smoteSample result=r/
    table="cars",
    inputs = {"Make", "Type", "MPG_City", "Weight", "EngineSize"},
    nominals = {"Make", "Type"},
    k=3,
    seed=123,
    numSamples=500,
    casOut={name="out",replace=TRUE};
    print r;
 run;
 quit;

The table parameter names the input data table to be analyzed. The inputs parameter specifies the input variables to use in SMOTE oversampling. The nominals parameter specify the list of nominal variables for analysis. Note that the character variables should be specified as nominal. The k parameter requests the three nearest neighbors to use for data generation. The seed parameter specifies 123 as the random seed to use in partitioning. The numSamples parameter requests that 500 new synthetic data points be generated. The casOut parameter requests that the new samples be stored in a table named mycas.out.

Then the correlation of the new synthetic data is analyzed using the following PROC CORR statements. It is found that SMOTE generates data whose correlation patterns are very similar to those of the original data.

 title "Pearson Correlation and Matrix Plot of Synthetic Data";
 proc corr data=mycas.out noprob plots=matrix(hist);
    var MPG_City Weight EngineSize;
    ods select PearsonCorr MatrixPlot;
 run;

Output 36.1.3 and Output 36.1.4 show the Pearson correlation and the scatter plot matrix of the synthetic data, respectively.

Output 36.1.3: Pearson Correlation of the Synthetic Data

Pearson Correlation and Matrix Plot of Synthetic Data

The CORR Procedure

Pearson Correlation Coefficients, N = 500
 MPG_CityWeightEngineSize
MPG_City1.00000-0.83987-0.78724
Weight-0.839871.000000.87351
EngineSize-0.787240.873511.00000


Output 36.1.4: Scatter Plot Matrix of the Synthetic Data

 Scatter Plot Matrix of the Synthetic Data


Using Synthetic Data to Capture the Correlations of Variables in the Original Data

This example is not available for the Lua programming language.

Using Synthetic Data to Capture the Correlations of Variables in the Original Data

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the cars data to the comma-separated-value (CSV) file cars.csv and then use the following code to load the CSV file into CAS:

s.upload_file('cars.csv')

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

The following code loads the smote action set and runs the smoteSample action on the cars data table:

s.loadactionset(actionset="smote")
s.smoteSample(table={"name":"cars"},
              inputs=["Make", "Type", "MPG_City", "Weight", "EngineSize"],
              nominals=["Make", "Type"],
              k=2,
              seed=123,
              numSamples=500,
              casOut={"name":"out", "replace":True}
             )

table_out=s.CASTable('out')
print(table_out.fetch(to=20))


Using Synthetic Data to Capture the Correlations of Variables in the Original Data

This example is not available for the R programming language.

Last updated: August 04, 2026