Incrementing tables more than once per respondent
When bit is better than fld shows how
bit provides an quick and easy method of updating the cells in a table by more than one per respondent. In the example, the cells of the table show the number of visits per restaurant, but the base shows the number of respondents eligible for inclusion in the table.
Although a table of this type immediately highlights restaurants which were visited more than once per respondent, there might be times when you want the base to be calculated on the same basis as the rest of the table; that is, it should be a count of viewings rather than of respondents. To obtain a table of this type you need to increment the base once per field rather than once per respondent. This means reading and tabulating one field at a time. The statement which lets you do this is process. This is an edit statement which sends the record temporarily to the tabulation section.
This example rewrites the restaurants example using
process and compare the results with the ones we obtained using
bit. For more information about
process and further examples, see
Going temporarily to the tab section.
The edited version contains a loop which copies the contents of each field in turn into some spare columns and then sends the record to the tabulation section for analysis. To make sure that all tables are not incremented more than once per respondent, the code sets a flag in another spare column which you can use as a filter on the table which requires the extra updating.
The edit is:
ed
/* set a flag for use as filter in tab section
c181='1'
/* take each field in turn
do 5 t1 = 112,116,2
if (c(t1,t1+1)=$ $) go to 5
c(182,183) = c(t1,t1+1)
/* skip to tab section
process
/* back from tab section, so try the next field
5 continue
/* reset filter flag for other tables
c181=' '
.
end
The tabulation section looks like this:
/* filter table so it is only updated for process fields
tab filmax region;c=c181'1'
ttlBase: Number of Visits
/* remove filter for all other tables
flt;c=c181' '
tab ax1 bk1
.
l filmax
fld (c(182,183));Base;Mexican;Indian;French;
+Italian;Chinese;None of these=$&&$
The record passes through the entire tabulation section but only tables in which the spare column contains a ‘1’ are updated. Once all fields have been dealt with, the edit resets this column to blank so that when the edit finishes Quantum can create the other tables in the usual way.
To compare the results of using bit and process, look at this record:
0 ---+--- 1
020402
| With bit and inc= | With process |
---|
Base | 1 | 3 |
Mexican | 0 | 0 |
Indian | 2 | 2 |
French | 0 | 0 |
Italian | 1 | 1 |
Chinese | 0 | 0 |
None of these | 0 | 0 |
The counts for the individual restaurants are the same with both methods. bit and inc increment each table cell by the value of the restaurant’s cell in the array but, because the record passes through the tabulation section once, the base is incremented only once per respondent. With process the record passes through the tabulation section once per restaurant; the base and the individual restaurant counts are incremented each time this happens.
See also