TableEditor
Control
elements
enable your extension node to access SAS data sets that are accessible
by the SAS Enterprise Miner server or that are generated by your extension
node's server code. The server code that is required for a
TableEditor
Control
is
typically minimal. The essential purpose of the server code is to
provide a way for the SAS Enterprise Miner server to identify and
track the data sets or files that are to be accessed by the
Control
.
The
Control
elements also typically provide
a way for you to add more sophisticated functionality beyond the minimal
requirements.
The following XML code
illustrates the most basic configuration of a
String
Property
with
a
TableEditor
Control
:
<Property description="write your own description here"
displayName="TableEditor Control Example"
name="TableEditor"
type="String">
<Control>
<TableEditor key="COMPANY">
<Actions>
<Open name="OpenTable" />
<Close name="CloseTable" />
</Actions>
</TableEditor>
</Control>
</Property>
This configuration requires
a single
Control
element. This
Control
element
has no attributes. Nested inside of this
Control
element
is a single
TableEditor
element. The
TableEditor
element
has a
key
attribute. The value of the
key
attribute
is the name of a file key that you register using the %EM_REGISTER
macro. In this example, the node prefix is EXMPL and the
key
is
COMPANY, so the name of the table is EMWS.EXMPL_COMPANY.
You also need some code
that associates a data set with that
key
.
For example, you might have code in the CREATE action that registers
the
key
, COMPANY, and a SAS DATA step that
associates the
key
with the data set Sashelp.Company:
%em_register(type=data,key=COMPANY,property=Y);
data &EM_USER_COMPANY;
set sashelp.company;
run;
If you want the table
to be available before run time, place the code that associates the
data set with the key in the CREATE action. However, in some cases,
the table that you are opening with the
TableEditor
Control
is
not created until after the node is run. The data set might be created
by a process within the TRAIN code. In that case, you could still
register the key in your CREATE code, but the code that associates
the key with the data set would be in your TRAIN code. If the user
attempted to open the table before the node was run, an error message
would appear indicating that the table does not exist.
Nested within the
TableEditor
element
is an
Actions
element. The
Actions
element
associates a block of SAS code with a user action. Inside of the
Actions
element
are an
Open
element and a
Close
element;
both have a
name
attribute. In your node's
main program, you can add code that might look like this:
%if %upcase(&EM_ACTION) = OPENTABLE %then %do;
filename temp catalog 'sashelp.emext.example_actions.source';
%include temp;
filename temp;
%OpenTable;
%end;
%if %upcase(&EM_ACTION) = CLOSETABLE %then %do;
filename temp catalog 'sashelp.emext.example_actions.source';
%include temp;
filename temp;
%CloseTable;
%end;
The values of the
name
attributes
correspond to the names of the actions that are executed when the
user either opens or closes the table. The following actions occur
when the user opens the table by clicking the ellipsis (
) icon:
-
The &EM_ACTION macro variable
is assigned the value of the
Open
action
(for example,
OpenTable
) before the server
code is processed.
-
The &EM_TABLE macro variable
is initialized; it resolves to the name of the table (for example,
EMWS. EXMPL_COMPANY).
-
The
OpenTable
action
that is specified in the
Open
element executes
before a copy of the table is returned to the client.
-
A temporary table named WORK.key
is created (for example, WORK.COMPANY). This table stores any changes
that the user makes to the original table.
The following actions
occur when the user closes the table:
-
The %EM_ACTION macro variable is
assigned the value of the
Close
action (for
example,
CloseTable
) before the server code
is processed.
-
The &EM_TABLE macro variable
is initialized; it resolves to the name of the table (for example,
EMWS. EXMPL_COMPANY).
-
The &EM_TEMPTABLE macro variable
is initialized; it resolves to the name of the temporary table that
contains any changes to the table that the user made (for example,
WORK.COMPANY).
-
The
CloseTable
action
that is specified in the
Close
element executes.
-
The permanent table is overwritten
by the temporary table so that any changes made by the user are recorded
in the permanent table.
You must have at least
one named action (
Open
or
Close
)
specified in the XML properties file for a
TableEditor
Control
.
However, you are not required to write any code or to include a call
to the action in your main program. When you do not have any code
that you want to execute when the table is opened or closed, the
Actions
,
Open
,
and
Close
elements act as placeholders.
When implemented, the
icon appears in the Value column of the Properties
panel.
When a user clicks the
icon, a
SAS Table Editor window
appears, displaying the table that is associated with the Control.
In this example, the
entire table is displayed when the user clicks the
icon and the table cannot be edited. Adding a
Column
element
with nested
Column
elements enables you to
control which variables appear in the table and whether a variable's
values can be edited by the user. In the following example, the
Control
configuration
restricts which variables are displayed in the table and enables the
user to edit the values of those variables:
<Property description="write your own description here"
displayName="TableEditor Control Example"
name="TableEditor"
type="String">
<Control>
<TableEditor key="COMPANY">
<Actions>
<Open name="OpenTable"/>
<Close name="CloseTable"/>
</Actions>
<Columns displayAll="N">
<Column name="DEPTHEAD"
type="String"
editable="Y"/>
<Column name="JOB1"
type="String"
editable="Y"/>
<Column name="LEVEL3"
type="String"
editable="Y"/>
<Column name="N"
type="int"
editable="Y"/>
<Column name="LEVEL4"
type="String"
editable="Y"/>
</Columns>
</TableEditor>
</Control>
</Property>
In the
Columns
element,
the
displayAll
attribute has a value of
N.
This indicates that only those variables that are specifically identified
by
Column
elements should appear when the
table is opened. Four
Column
elements are
specified. In each
Column
element, there
are three attributes defined as follows:
-
name
—
specifies the name of the variable to display.
-
type
—
specifies one of four supported types of variables. The supported
types are as follows:
Note: These values are case-sensitive.
-
editable
—
indicates whether the user can modify the variable's values.
Valid values are Y or N.
When the
editable
attribute
of a Column element is set to
Y, the user can
edit the values of the corresponding variable by entering a new value
in the
SAS Table Editor window.
You can also add
Range
Control
elements
to restrict the values that can be used to edit the values in the
table. For example, suppose you add a
Range
Control
to
the
N Column
element
as follows:
<Property description="write your own description here"
displayName="TableEditor Control Example"
name="TableEditor"
type="String">
<Control>
<TableEditor key="COMPANY">
<Actions>
<Open name="OpenTable" />
<Close name="CloseTable" />
</Actions>
<Columns displayAll="N">
<Column name="DEPTHEAD"
type="String"
editable="Y">
</Column>
<Column name="JOB1"
type="String"
editable="Y"/>
<Column name="LEVEL3"
type="String"
editable="Y"/>
<Column name="LEVEL4"
type="String"
editable="Y"/>
<Column name="N"
type="int"
editable="Y">
<Control>
<Range min="1" max="3" />
</Control>
</Column>
</Columns>
</TableEditor>
</Control>
</Property>
Now when the user tries
to edit the
N column of the table, they must
enter an integer value between the
min
and
max
values
specified. If they enter a value that is outside of that range, the
value of
N is set to missing in that row
of the table.