Data Science Pilot Action Set

Mutual-Information-Based Analysis of Missing Patterns Using the analyzeMissingPatterns Action

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 Visual Data Mining and 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.

The following DATA step creates the reference data table mycas.dmagecr in your CAS session, keeping only the age, amount, coapp, duration, foreign, job, and good_bad variables. To illustrate how you can use the analyzeMissingPatterns action to analyze missing patterns in a data table, artificially created and highly correlated missing patterns are created in the reference data table. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

data mycas.dmagecr;
   set sampsio.dmagecr;
   keep age amount coapp duration foreign job good_bad;
   call streaminit(12345);
   r = rand("Uniform");
   if r < 0.1 then
      do;
         age = .;
         amount = .;
      end;
   else if r < 0.2 then
      do;
         duration = .;
      end;
run;

The following statements run the analyzeMissingPatterns action to analyze the missing patterns in the input variables. The action outputs a data table that contains the mutual information of the variables among themselves and versus the target variable. It outputs the results of the analysis in an output data table named miss_pattern_out.

proc cas;
   loadactionset "dataSciencePilot";
   dataSciencePilot.analyzeMissingPatterns
                            / table     = "DMAGECR"
                              casOut    = {name    = "MISS_PATTERN_OUT",
                                           replace = True}
                              inputs    = {{name   = "age"},
                                           {name   = "amount"},
                                           {name   = "coapp"},
                                           {name   = "duration"},
                                           {name   = "foreign"},
                                           {name   = "job"}}
                              nominals  = {"coapp",  "foreign", "job"}
                              ;
   run;
   fetch / table = "MISS_PATTERN_OUT";
   run;
quit;

The table parameter names the input reference data table. The casOut parameter names the output data table. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.

The CAS output table is shown in Figure 1.

Figure 1: Missing Pattern

Results from table.fetch

Selected Rows from Table MISS_PATTERN_OUT
_Index_FirstVariableSecondVariableTypeMINormMISUEntropyPerChange
1agecoapp_mindmind_1000.
2ageforeign_mindmind_2000.
3agejob_mindmind_3000.
4agecoapp_mindnonm_10.00035428730.0266143510.00069680010.065795892
5ageforeign_mindnonm_20.00084885090.04118569610.00240196220.3717095636
6agejob_mindnonm_30.00151081190.05492780090.00159718840.1068916187
7ageamount_mindnonm_50000
8ageduration_mindnonm_60.00934433310.13607026120.00458037740.2619951725
9amountcoapp_mindmind_1000.
10amountforeign_mindmind_2000.
11amountjob_mindmind_3000.
12amountage_mindmind_40.47843386550.78479673181100
13amountcoapp_mindnonm_10.00035428730.0266143510.00069680010.065795892
14amountforeign_mindnonm_20.00084885090.04118569610.00240196220.3717095636
15amountjob_mindnonm_30.00151081190.05492780090.00159718840.1068916187
16amountage_mindnonm_40000
17amountduration_mindnonm_60.00934433310.13607026120.00458037740.2619951725
18durationcoapp_mindmind_1000.
19durationforeign_mindmind_2000.
20durationjob_mindmind_3000.


Mutual-Information-Based Analysis of Missing Patterns Using the analyzeMissingPatterns Action

This section contains Lua 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 dmagecr data to the comma-separated-value (CSV) file dmagecr.csv and then use the following code to load the CSV file into CAS:

s:loadtable{casLib="casuser", path="dmagecr.csv"}

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

The following statements run the analyzeMissingPatterns action to analyze the missing patterns in the input variables. The action outputs a data table that contains the mutual information of the variables among themselves and versus the target variable. It outputs the results of the analysis in an output data table named miss_pattern_out.

s:loadactionset{actionset="dataSciencePilot"}

s:dataSciencePilot_analyzeMissingPatterns {
                              table     = {name ="DMAGECR"},
                              casOut    = {name    = "MISS_PATTERN_OUT",
                                           replace = True},
                              inputs    = {{name   = "age"},
                                           {name   = "amount"},
                                           {name   = "coapp"},
                                           {name   = "duration"},
                                           {name   = "foreign"},
                                           {name   = "job"}},
                              nominals  = {"coapp",  "foreign", "job"}
}

s:fetch{table="MISS_PATTERN_OUT"}

The table parameter names the input reference data table. The casOut parameter names the output data table. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.

For example output from the action, see the CASL code examples.

Mutual-Information-Based Analysis of Missing Patterns Using the analyzeMissingPatterns Action

This section contains R 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 dmagecr data to the comma-separated-value (CSV) file dmagecr.csv and then use the following code to load the CSV file into CAS:

m <- cas.read.csv(s, "dmagecr.csv", casOut=list(name="dmagecr"))

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

The following statements run the analyzeMissingPatterns action to analyze the missing patterns in the input variables. The action outputs a data table that contains the mutual information of the variables among themselves and versus the target variable. It outputs the results of the analysis in an output data table named miss_pattern_out.

cas.loadActionSet(s,"dataSciencePilot")

cas.dataSciencePilot.analyzeMissingPatterns(
   s,
   table     = list(name ="DMAGECR"),
   casOut    = list(name = "MISS_PATTERN_OUT",
                    replace = True),
   inputs    = list("age",
                    "amount",
                    "coapp",
                    "duration",
                    "foreign",
                    "job"),
   nominals  = list("coapp",
                    "foreign",
                    "job")
)

cas.fetch(s, table = list(name = "MISS_PATTERN_OUT"))

The table parameter names the input reference data table. The casOut parameter names the output data table. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.

For example output from the action, see the CASL code examples.

Mutual-Information-Based Analysis of Missing Patterns Using the analyzeMissingPatterns Action

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 dmagecr data to the comma-separated-value (CSV) file dmagecr.csv and then use the following code to load the CSV file into CAS:

s.upload_file('dmagecr.csv')

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

The following statements run the analyzeMissingPatterns action to analyze the missing patterns in the input variables. The action outputs a data table that contains the mutual information of the variables among themselves and versus the target variable. It outputs the results of the analysis in an output data table named miss_pattern_out.

s.loadactionset(actionset="dataSciencePilot")
s.dataSciencePilot.analyzeMissingPatterns(
     table     = {"name" : "DMAGECR"},
     inputs    = ["age", "amount", "coapp", "duration", "foreign", "job"],
     nominals  = ["coapp", "foreign", "job"],
     casOut    = {"name" : "MISS_PATTERN_OUT", "replace" : True}
 )
s.fetch(table = {"name": "MISS_PATTERN_OUT"})

The table parameter names the input reference data table. The casOut parameter names the output data table. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.

For example output from the action, see the CASL code examples.

Last updated: November 04, 2020