Level 2 preproc Form 2.1 preproc Field 2.1.1
preproc Field 2.1.1 postproc Form 2.1 postproc repeat for other Level 2 postproc Level 1 postproc Form File postproc
MICS4 Data Processing Workshop
Ending a Level
• You must prematurely finish a level if – the last variable in the data path is not the last variable on the questionnaire – there are no more woman or children’s under-five questionnaires left for the HH • This is accomplished using the endlevel command
MICS4 Data Processing Workshop
The endlevel Command
• The effect of the endlevel command depends upon its context/location: – In a field/roster/form proc, control passes to the current level’s postproc – In a level 2 or higher postproc, control passes to the next highest level’s postproc – In a level 1 proc, control passes to the application, i.e., the form file’s postproc
MICS4 Data Processing Workshop
Operator vs. System Controlled
• Operator-controlled: the keyer has some/ all control on the data entry path • System-controlled: the keyer has no control over the data entry path – go to options data entry – choose “system controlled” – (while you are there, make all alphanumeric variables upper case)
MICS4 Data Processing Workshop
Ending a Group
• A group is a roster or multiply-occurring form • Is terminated by using the endgroup command • Passes control to the group’s postproc— all intervening logic (in other form/roster items) is skipped
MICS4 Data Processing Workshop
User-defined Variables
• User-defined variables must be declared in the PROC GLOBAL section and as implied, are global in scope • Numeric working variables can be declared together – numeric var1, var2 ; • Alphanumeric variables must be declared separately: – alpha(length) avar1; – alpha(length) avar2;
MICS4 Data Processing Workshop
User-defined Variables (cont)
• All variables must be declared in the preproc of the form_files procedure • User-defined variables should be assigned a value within the preproc of the form_files, e.g., minab = 144 ; • You should give a description of your variable at either the place of declaration or initialization, e.g., numeric minab; {min. age at first birth in months}
MICS4 Data Processing Workshop
Recoding Variables
• To more easily assign values to a variable based on another variable, use recode • The following logic recodes women’s age into groups: recode WB2 => agegrps; 15-19 20-24 => => 1 2 ; ; => 3 ; endrecode ;
MICS4 Data Processing Workshop
if command
Use the if command to check for a condition: if HH9 <> 1 then skip to HH16; endif ; if (HH9= 1 (HH9 in and HH11= 0 ) or 2:4,6 and HH11<> 0 ) reenter ; endif ; then
MICS4 Data Processing Workshop
Generating Error Messages
• Example: If the cluster number is invalid, we can show the operator a message to explain what the problem is; for example, errmsg ( “Cluster number invalid” ); • However, to be more useful, we should tell them what the valid range is; to do this, we can pass in parameters to the command as follows: errmsg ( “Cluster number invalid, expected range %d to %d” , MinClust, MaxClust);
MICS4 Data Processing Workshop
Error Message Parameters
• The values of any variables listed after the error message number will be passed to the error message • Parameters are displayed in the error message using – %d for numeric values – %s for alphanumeric values (i.e., text)
MICS4 Data Processing Workshop
Streamlining Error Messages
• Suppose we need to repeat the same message several times in the file —what should we do?
• We can assign unique numbers to each error message • We can keep all error messages in the message file (.mgf)
MICS4 Data Processing Workshop
Sample Error Messages
• Our earlier message (and maybe one we could use for that HH result code earlier) would now be simplified to: errmsg( 1 , MinClust, MaxClust); errmsg( 2 , HH9, HH11); • And the message file would look something like: 0001 0002 Cluster number invalid, expected range %d to %d HH result code (%d) doesn’t agree with number of HH members (%d)
MICS4 Data Processing Workshop
Modifying Your Test Application
• Add logic to – check if the household number is consistent • display message and add reenter command if not – implement the HH result code skip – check the date of interview is internally consistent • display message and force reentry if not • Compile your application, resolve any errors • Save your application ()
MICS4 Data Processing Workshop
Testing your Application
• Click once on the execute button on toolbar ( ), or press to run • Use NoData.dat as your datafile • Enter a case (i.e., a questionnaire)
MICS4 Data Processing Workshop