I am new to CSPRO and hence this forum. I need help, infact urgent help on calculating age from interview month and interview year. Interview month and year are coming from cover section of the questionnaire a different record type: cover or common section. whilst birth month =s1q3a and birth year = s1q3b are coming from another record type: household roster. same as age=s1q4a. I wrote the code below which is supposed to calculate age and compare it to age on the questionnaire. It compiles but cannot compare. Can any one help with want went wrong??
numeric calculatedAge = int( (cmcode(intervmonth,intervyear) - cmcode(s1q3a,s1q3b) ) / 12 );
if s1q4a <> calculatedAge then
errmsg("Date of birth (%d/%d) and age (%d) are inconsistent.",
S1Q3A, S1Q3B,
S1Q4B)
select("Correct age in years", S1Q4B);
endif;
Calculating Age
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: Calculating Age
The logic looks correct except that you are using S1Q4B in the error message and S1Q4A in the if. Which one is the age in years?
If that isn't the problem then I suspect that one or more of the inputs to your check is not correct. I would add an errmsg statement just to print out the inputs to the check to see if there is something wrong. For example by adding the following after computing the calculated age:
errmsg("interview date = (%d/%d) cmcode = %d birth date = (%d/%d) cmcode = %d calc age = %d",
intervmonth,intervyear,cmcode(intervmonth,intervyear),s1q3a,s1q3b,cmcode(s1q3a,s1q3b),
calculatedAge);
You may find that one of the inputs in notappl or otherwise not valid.
If that isn't the problem then I suspect that one or more of the inputs to your check is not correct. I would add an errmsg statement just to print out the inputs to the check to see if there is something wrong. For example by adding the following after computing the calculated age:
errmsg("interview date = (%d/%d) cmcode = %d birth date = (%d/%d) cmcode = %d calc age = %d",
intervmonth,intervyear,cmcode(intervmonth,intervyear),s1q3a,s1q3b,cmcode(s1q3a,s1q3b),
calculatedAge);
You may find that one of the inputs in notappl or otherwise not valid.
-
gbos
- Posts: 51
- Joined: June 18th, 2015, 7:49 pm
Re: Calculating Age
Thanks Josh for the prompt reply to my issue. Just to clarify, s1q4a is the Age am trying to compare calculated Age to. I corrected s1q4b to s1q4a in the error message still i don't seem to get the desired result. For instance if some one was born 2014 and I enter 20 years for his age, the input is accepted without any alert warning whatsoever.
Now I will upload my application for you to have a close look at. I hope to hear from you the soonest. Thanks in advance.
Now I will upload my application for you to have a close look at. I hope to hear from you the soonest. Thanks in advance.
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: Calculating Age
Please put in the errmsg as suggested and let me know what you see.
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: Calculating Age
Never mind about the output from errmsg. You will not see any since it will never be run. The problem is that you have skips the proc above the age check which will prevent you from ever getting to that code:
if $ >=6 then
skip to s1q5;
endif;
if $<6 then
move to s1q4b;
endif;
For anyone greater than or equal to 6 you will skip to s1q5 and for anyone less than six you skip to s1q4b. The skip immediately leaves the proc you are in without executing the rest of the proc. Put the skips AFTER your age check and it should work fine.
if $ >=6 then
skip to s1q5;
endif;
if $<6 then
move to s1q4b;
endif;
For anyone greater than or equal to 6 you will skip to s1q5 and for anyone less than six you skip to s1q4b. The skip immediately leaves the proc you are in without executing the rest of the proc. Put the skips AFTER your age check and it should work fine.
-
Guest
Re: Calculating Age
Thanks Josh: I don't know how many times I have to. Finally,it worked!!!
. Like I said, in my first post am new to CSPRO. I shall be posting other difficulties whilst I continue to build my application, if the need arises. However, so far so good. Bravo!!!
My warm Regards,
Lamin Janneh (gbos)
My warm Regards,
Lamin Janneh (gbos)
-
gbos
- Posts: 51
- Joined: June 18th, 2015, 7:49 pm
Re: Calculating Age
Thanks Josh: I don't know how many times I have to. Finally,it worked!!!
. Like I said, in my first post am new to CSPRO. I shall be posting other difficulties whilst I continue to build my application, if the need arises. However, so far so good. Bravo!!!
My warm Regards,
Lamin Janneh (gbos)
My warm Regards,
Lamin Janneh (gbos)