Creating axis expressions in the OnBeforeJobStart Event section
Creating axis expressions and exporting to IBM SPSS Statistics contains an example of setting up axis expressions in the Metadata section of a data management script. However, you might want to use a standard axis expression for some variables. For example, you might want to use the same expression to summarize some numeric variables. This is usually easier using mrScriptBasic rather than mrScriptMetadata. For examples of using this technique in a standalone .
mrs file, see
Creating axis expressions in your script.
If you want to use this technique in a data management script, you would typically do it in the OnBeforeJobStart Event section. For example, the TablesDefineAxesExportToRDB.dms sample includes an OnBeforeJobStart Event section that creates axis expressions for all numeric variables that do not already have one.
Event(OnBeforeJobStart, "Autosummarize the numeric variables")
Dim MDM
' Create the MDM object
Set MDM = CreateObject("MDM.Document")
' Open all versions of the Short Drinks sample
MDM.Open(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\short_drinks.mdd", "{..}")
' Set up axis expressions for all numeric variables
' that don't already have one
CreateAxisExpressions(MDM.Fields)
Sub CreateAxisExpressions(Fields)
Dim Field
' Loop through all fields and create an axis expression for
' all of the numeric variables that don't already have one
For Each Field In Fields
Select Case Field.ObjectTypeValue
Case ObjectTypesConstants.mtVariable ' Simple variable
If Field.DataType = mr.Long Or Field.DataType = mr.Double Then
' It's a numeric
If Field.AxisExpression.IsEmpty() Then
' It hasn't already got an axis expression, so create one
Field.AxisExpression = "{min 'Minimum' min(" + Field.FullName + _
"), max 'Maximum' max(" + Field.FullName + _
"), mean 'Mean' mean(" + Field.FullName + _
"), StdDev 'Standard deviation' StdDev(" + Field.FullName + _
"), StdErr 'Standard error' StdErr(" + Field.FullName + ")}"
End If
End If
Case ObjectTypesConstants.mtClass, ObjectTypesConstants.mtCompound, _
ObjectTypesConstants.mtGrid, ObjectTypesConstants.mtArray
' It's a container, process the contents
CreateAxisExpressions(Field.Fields)
End Select
Next
End Sub
MDM.Save(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Output\short_drinks_with_axis.mdd")
MDM.Close()
End Event
The highlighted lines show a section from the OnBeforeJobStart event section that loops through all numeric variables to check for the presence of an axis expression. If none exists, the script creates an axis expression consisting of a minimum, maximum, mean, standard deviation, and standard error element for each variable. The script also contains a Metadata section that creates an axis expression for a specific categorical element (see
Creating special elements in metadata using a data management script for further details) and an OnAfterJobEnd event section that creates the tables.
To run this sample, you need to have the UNICOM Intelligence Professional Tables Option and access to a SQL Server installation and appropriate user access rights. Before running the sample, you need to set up a SQL Server database called TablesDefineAxesExportToRDB. If you run this script more than once, you must delete the records in the database created by the previous run, otherwise the serial numbers will be duplicated and errors will result.
The example in this topic is in a file called
TablesDefineAxesExportToRDB.dms that comes with the UNICOM Intelligence Developer Documentation Library. For more information, see
Table scripting sample Data Management scripts.
See