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

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

Embed Size (px)

Citation preview

Page 1: MICS Data Processing Workshop User-Defined and Built-In Functions

MICS Data Processing Workshop

User-Defined and Built-In Functions

Page 2: 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

Page 3: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 4: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 5: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 6: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 7: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 8: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 9: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 10: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 11: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 12: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 13: MICS Data Processing Workshop User-Defined and Built-In Functions

Using adjlba and adjuba

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

if t < 0 then

errmsg(1003);

else

ldob = t

endif;

Page 14: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 15: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 16: MICS Data Processing Workshop User-Defined and Built-In Functions

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)

Page 17: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 18: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 19: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 20: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 21: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 22: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 23: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 24: MICS Data Processing Workshop User-Defined and Built-In Functions

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

Page 25: MICS Data Processing Workshop User-Defined and Built-In Functions

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”

Page 26: MICS Data Processing Workshop User-Defined and Built-In Functions

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 “