MICS Data Processing Workshop User-Defined and Built-In Functions

Preview:

Citation preview

MICS Data Processing Workshop

User-Defined and Built-In Functions

Built-In Functions

CSPro has a wide range of built-in functions

Not possible to modify Most built-in functions are well-

documented in the help system– But we'll discuss a few that are not

Century Month Code

January 1900 = CMC 1 December 1900 = CMC 12 January 1901 = CMC 13 April 2000 = CMC 1204 April 2001 = CMC 1216

CMC = (Year-1900)*12 + Month

The cmcode Function

Purpose: calculate the CMC of a month/year

Syntax: cmcode(month,year) Returns:

– if month and year valid: CMC of month/year– if month or year invalid: 9999

The setlb Function

Purpose: calculate the lower CMC bound for an event

Syntax: setlb(month,year,minimum) Returns:

– if month and year valid: CMC of month/year– if only year valid: CMC of 1/year– if year invalid: minimum

The setub Function

Purpose: calculate the upper CMC bound for an event

Syntax: setub(month,year,maximum) Returns:

– if month and year valid: CMC of month/year– if only year valid: CMC of 12/year– if year invalid: maximum

Example of setlb and setub

Suppose– WM8M = 98– WM8Y = 1957

Using setlb and setub set– ldob = setlb(WM8M,WM8Y,0) = 685– udob = setub(WM8M,WM8Y,9999) = 696

The adjlba Function

Purpose: adjust lower CMC bound for an event using an age

Syntax: adjlba(lcmc,ucmc,di,di,age) Arguments:

– lcmc is lower bound of event– ucmc is upper bound of event– di is date of interview

Denote resulting lower bound rlb

The adjlba Function

Returns:– if rlb >= lcmc and rlb <= ucmc: rlb– if rlb < lcmc: lcmc– if rlb > ucmc: -1

Calculates:– rlb = di - age*12 - 11– i.e., calculate minimum date of birth

The adjuba Function

Purpose: adjust upper CMC bound for an event using an age

Syntax: adjuba(lcmc,ucmc,di,di,age) Arguments:

– lcmc is lower bound of event– ucmc is upper bound of event– di is date of interview

Denote resulting lower bound rub

The adjuba Function

Returns:– if rub >= lcmc and rub <= ucmc: rub– if rub > ucmc: ucmc– if rub < lcmc: -1

Calculates:– rub = di - age*12– i.e., calculate maximum date of birth

Example of adjlba and adjuba

Suppose– DOI is 06/2005 so di = 1266– WM8M = 98, WM8Y = 1957 and WM9 = 48– Thus

ldob = 685 and udob = 696 rlb = 679 and rub = 690

Using setlb and setub set– t = adjlba(ldob,udob,di,di,wm9) = 685– t = adjuba(ldob,udob,di,di,wm9) = 690

Using adjlba and adjuba

t = adjlba(ldob,udob,diwm,diwm,WM9);

if t < 0 then

errmsg(1003);

else

ldob = t

endif;

User-Defined Functions

User-defined functions (UDF) can be created in the global procedure

There are 14 UDF in the data entry application

These functions do not need to be modified

But they do need to be understood

Anthropometry UDF

The first 7 UDF primarily concern anthropometry

Six of these UDF concern only anthropometry and will not be discuss further

The seventh is named agemth It calculates a child’s age in months

The agemth UDF

Syntax: agemth(bd,bm,by,md,mm,my) Returns:

– child’s age in months if birth day, month and year are valid

– child’s age in months using 15 as day if only birth month and year are valid

– special if only birth year is valid Purpose: calculates most accurate age in

months possible (used for anthropometry)

The valid UDF

Syntax: valid(xvar) Returns:

– 1 if value of xvar is not special and less than 96

– 0 otherwise Purpose: checking that a variable has a

valid value

The NAtoZero UDF

Syntax: NAtoZero(xvar) Returns:

– 0 if value of xvar is not applicable– value of xvar otherwise

Purpose: permits one to use variables that may be not applicable in summations

The vdvalid UDF

Syntax: vdvalid(vday,vmonth,vyear) Returns:

– 0 if vaccination date is valid– 1 otherwise

Purpose: checking that a vaccination date is valid

The vdoi UDF

Syntax: vdoi(vday,vmonth,vyear) Returns:

– 0 if vaccination date is before date of interview

– 1 otherwise Purpose: checking the vaccination is not

after the date of interview

The vdob UDF

Syntax: vdob(vday,vmonth,vyear) Returns:

– 0 if vaccination date is before a child’s date of birth

– 1 otherwise Purpose: checks vaccination date is after

date of birth

The vseq UDF (Editing Only!)

Syntax: vseq(v1d,v1m,v1y,v2d,v2m,v2y) Returns:

– 0 if vaccination one was given before vaccination 2

– 1 otherwise Purpose: checks that sequential

vaccinations (e.g., polio) are in the correct order

The vmatch UDF (Editing Only!)

Syntax: vmatch(v1d,v1m,v1y,v2d,v2m,v2y)

Returns:– 0 if vaccinations given on the same date– 1 otherwise

Purpose: check if vaccinations often given on the same date (e.g., polio and DPT) were given on the same date

The endmess UDF

Syntax: endmess() Action: in add mode displays options

– 1 “Review Questionnaire”– 2 “Next Questionnaire”

Returns:– 1 if data entry operator selects “review

questionnaire” option from menu– 0 otherwise

The alphachk UDF

Syntax: alphachk(alphamask) Requirement: precede with assignment

statement– alphavar = $

Input: acceptable values for an alphanumeric variable– e.g., for WS6 alphamask is “ABCDEFXZ”

The alphachk UDF

Actions:– checks responses in alphavar are in alphamask– checks responses in alphavar are in

alphabetical order– checks that if ? is in alphavar then it is the

only response in alphavar– places each response in alphavar in the

location defined by its subitem e.g., for WS6, “ACEF ” becomes “A C EF “