Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "MICS Data Processing Workshop User-Defined and Built-In Functions."— Presentation transcript:

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

2 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

3 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

4 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

5 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

6 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

7 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

8 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

9 The adjlba Function Returns: – if rlb >= lcmc and rlb <= ucmc : rlb – if rlb < lcmc : lcmc – if rlb > ucmc : -1 Calculates: – rlb = di - age* – i.e., calculate minimum date of birth

10 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

11 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

12 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

13 Using adjlba and adjuba t = adjlba(ldob,udob,diwm,diwm,WM9); if t < 0 then errmsg(1003); else ldob = t endif;

14 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

15 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 childs age in months

16 The agemth UDF Syntax: agemth(bd,bm,by,md,mm,my) Returns: – childs age in months if birth day, month and year are valid – childs 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)

17 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

18 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

19 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

20 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

21 The vdob UDF Syntax: vdob(vday,vmonth,vyear) Returns: – 0 if vaccination date is before a childs date of birth – 1 otherwise Purpose: checks vaccination date is after date of birth

22 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

23 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

24 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

25 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

26 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


Download ppt "MICS Data Processing Workshop User-Defined and Built-In Functions."

Similar presentations


Ads by Google