Passing a table name to a function
Posted: December 18th, 2014, 8:55 am
Is there a way to pass a table name as "t1101" below to a function?
The number of times t1101 above needs to be tallied depends on the variable {}V101, which represents region. This variable will be set "on the fly" and depends on the survey I'm looking at. It may be once, it may be more often, depending on the level of aggregation that is required. Therefor I need a function. Currently I'm passing a string in my function call. For example in a function called TxTab():
In the TxTab() function I then decide, depending on the string passed, which table needs to be tallied and how often (if more than once all other row variables must be set to not applicable):
For example:
I do have a few hundred of these calls in my program so It would really help if I could pass the table name and then just do something like:
with
Thanks for your help.
Han.
Code: Select all
crosstab float(1) t1101 chage2+sex2+pinter2+bsize+mothstat+mothbmi+v102w+{}V101+v106w+s_educ2+v190w+total
hghtage+wghthght+wghtage+numchild
exclude(rowzero,colzero,totals,percents,specval)
title( "Table 11.1 Nutritional status of children"," ",
"Percentage of children under five years classified as",
"malnourished according to three anthropometric indices of",
"nutritional status: height-for-age, weight-for-height, and",
"weight-for-age, by background characteristics, Countryxxxx" )
stub( "Background characteristic" );
Code: Select all
TxTab("t1101", rweight)
For example:
Code: Select all
function Txtab( alpha(15) TabName, tabweight )
do tally_t = 0 while tally_t <= tally_n
if tally_t then
s_region(tally_t,xregion);
endif;
if strip(TabName) = "t1101" then xtab( t1101, tabweight )
elseif strip(TabName) = "t1102" then xtab( t1102, tabweight )
etc....
............
...........
end;
Code: Select all
TxTab(Tab_Name, rweight)
Code: Select all
function Txtab( TableName, tabweight )
do tally_t = 0 while tally_t <= tally_n
if tally_t then
s_region(tally_t,xregion); // sets applicable row variables to not applicable
endif;
xtab( TableName, tabweight );
enddo;
if tally_n then s_region(0,xregion) endif; // resets the row variables
end;
Thanks for your help.
Han.