CSPro supports modifying individual cells in a table through postcalc logic.
As an example, take adding a third cell to the following table in which we will place the male to female ratio. The male to female ratio is simply the number of males divided by the number of females. We need add a new column to the table and then add postcalc logic to divide the number of males by the number of females and put the result in the new cell.
First, we must add the new column to the table as described in Adding Rows and Columns For Post Calculation.
Once the new column has been created, all that is left is to add the postcalc logic. Postcalc logic in CSPro tabulation applications is similar to working with arrays in a CSPro batch edit or data entry application. To access an individual cell in a table, use the table name followed by the indices of the row and column in parentheses:
<table name>(<row>, <column>)
where:
<table name> is the name of the table.
To see the names of the tables, click on the Tables tab in the bottom left of the CSPro window to show the Tables Tree and then select "Names in Trees" from the View menu or press Ctrl+T. This toggles between showing the table titles and the table names in the Tables Tree.
<row> is the row number in the table.
<column> is the column number in the table.
Row and column numbering starts at zero.
In this example, the following logic divides the number of males (row 0, column 1) by the number of females (row 0, column 2) and puts the result in male/female ratio (row 0, column 3):
TABLE1(0,3) = TABLE1(0,1) / TABLE1(0,2);
Note that column and row numbers start at zero, so the first column is column zero, the second column is column is column 1, etc…
To enter postcalc logic for a table, open the Tally Attributes (Table) dialog. You can then either type postcalc logic directly into the postcalc area or click on the "Edit" button next to the postcalc area to bring up a larger window to type in.
Once you have typed in the logic, press OK to dismiss the dialog and then run the table. You may need to change the number of the decimal places in the row, column or cell containing the calculated values.
Postcalc logic can contain numeric constants as well as table values. For example if you wanted men per 100 women rather than male to female ratio, you could use the following logic:
TABLE1(0,3) = 100 * TABLE1(0,1) / TABLE1(0,2);
This multiplies the result of the division by 100 to give the number of men per 100 women.
Multiple statements may be entered in postcalc, provided that each one is terminated by a semicolon. For example, if you wanted to calculate male to female ratio in column 3 and males per 100 females in column 4 you would write:
TABLE1(0,3) = TABLE1(0,1) / TABLE1(0,2);
TABLE1(0,4) = 100 * TABLE1(0,1) / TABLE1(0,2);
In fact, postcalc logic can contain nearly any of the statements and functions available in program logic in batch edit and data entry applications.
See also: Post Calculation For Rows, Columns and Ranges, Row and Column Indexing for Post Calculation