CALL TABLEPRINT
(table)
VAR=cols ID=IDName LABEL=label FIRSTOBS=firstObs NUMOBS=numObs COLHEADER="Names" | "Labels" | "None" JUSTIFY=just TEMPLATE=template COLTEMPLATE=colTemplates DYNAMIC=dynValues COLDYNAMIC=colDynValues ;
This subroutine is supported by the IML procedure and the iml action.
The TablePrint subroutine displays a table in the open ODS destinations. The subroutine takes the following required input argument:
- table
specifies an existing table.
The remaining arguments are optional and can be specified as keyword-value pairs. Specify these options outside the parentheses, as shown in the example in this section.
-
VAR=
cols
specifies the columns of the table, where cols can be a numeric vector of column numbers (such as {2 4 7}) or a character vector of names (such as {"X" "Y"}). If you omit this option, all variables appear in the table.
-
ID=
IDName
specifies the name of a column. The column (sometimes called a row header) appears on the left side of the table. You can specify a blank string to suppress the row headers. If you omit this argument or specify the special string "#", then row numbers are used for the row headers.
-
LABEL=
label
specifies a string for the name of the table. If you omit this option, the symbol name is used as the label. You can specify a blank string to suppress the label.
-
FIRSTOBS=
firstObs
specifies the first row of the table to display. If you omit this option, the table is displayed beginning with the first row.
-
NUMOBS=
numObs
specifies the total number of rows to display. If you omit this option, all rows of the table are displayed.
-
COLHEADER=
"Names" | "Labels" | "None"
specifies the form of the column headers that appear above columns. If you omit this option or specify the string "Names", then the column names are displayed. The string "Labels" displays column labels, if they exist. Column headers are not displayed if you specify the string "None" or a blank string.
-
JUSTIFY=
just
-
specifies the horizontal alignment for each column in a table, where just is a character vector with p elements that specifies the alignment for the first p columns. Each element of just is one of the following:
To center a column, use "C" or "Center".
To left-align a column, use "L" or "Left".
To right-align a column, use "R" or "Right".
To use the default alignment, use a space character ("膖"), "D", or "Default". By default, character columns are left-aligned and numeric columns are right-aligned.
If you specify a vector that has fewer elements than the number of columns, default values are used for the unspecified columns.
-
TEMPLATE=
template
specifies the name of an ODS table template to be used to display the SAS/IML table. For example, TEMPLATE=MyTemplate causes ODS to search for a template named MyTemplate and use that template to display the table.
-
COLTEMPLATE=
colTemplates
specifies the name of column templates that are used to display columns in the SAS/IML table. The colTemplates argument is a character vector with p elements that specifies template names for the first p columns. You can use the same template for multiple columns provided that the template has the GENERIC attribute. If you specify a vector that has fewer elements than the number of columns, default attributes are used to display the remaining columns. For example, the syntax COLTEMPLATE={CT1 CT2} looks for column templates named CT1 and CT2. It uses the CT1 definition to format the first column in the table and uses the CT2 definition to format the second column.
-
DYNAMIC=
dynValues
specifies values for dynamic variables in a template, where dynValues is a character matrix with k elements that specifies the values of k dynamic variables. Each element has the form "DynVar=IMLSym", where DynVar is the name of a dynamic variable in the template and IMLSym is the name of a SAS/IML scalar matrix that contains the value to use for the dynamic variable. The IMLSym symbol can be a character matrix or a numeric matrix. If the SAS/IML symbol has the same name as the dynamic variable, then you can use an alternate syntax in which an element has the form "DynVar". For examples, see Chapter 8, Mixed-Type Tables.
-
COLDYNAMIC=
colDynValues
specifies values for dynamic variables in a column template, where dynValues is a character matrix with k elements that specifies the values for k columns. One template can have multiple dynamic variables, so each element has the form "DynVar1=IMLSym1 DynVarD2=IMLSym …". For more information, see the DYNAMIC= option. For examples, see Chapter 8, Mixed-Type Tables.
The following statements show how to print a table. The first call displays the table by using default options. The result is shown in Figure 464. The second call specifies several options. The result is shown in Figure 465.
proc iml;
tbl = TableCreateFromDataSet("Sashelp", "Class", "WHERE=(sex='M')");
call TablePrint(tbl);
call TablePrint(tbl) VAR={"Height" "Age"}
ID="Name"
LABEL="Heights and Ages for Five Boys"
FIRSTOBS=3
NUMOBS=5
JUSTIFY={C L};
Figure 464: Display a Table by Using Default Options
| Alfred | M | 14 | 69 | 112.5 |
| Henry | M | 14 | 63.5 | 102.5 |
| James | M | 12 | 57.3 | 83 |
| Jeffrey | M | 13 | 62.5 | 84 |
| John | M | 12 | 59 | 99.5 |
| Philip | M | 16 | 72 | 150 |
| Robert | M | 12 | 64.8 | 128 |
| Ronald | M | 15 | 67 | 133 |
| Thomas | M | 11 | 57.5 | 85 |
| William | M | 15 | 66.5 | 112 |
Figure 465: Display a Table
| 57.3 | 12 |
| 62.5 | 13 |
| 59 | 12 |
| 72 | 16 |
| 64.8 | 12 |
The section Advanced Printing of Tables contains advanced examples of using the TABLEPRINT subroutine. Examples include the following:
Using a custom template to display a table
Headers that span multiple columns
Cells that are colored according to data values (traffic lighting)
Dynamic variables in templates whose values are specified at run time.