Date(YYYYMMDD) or Date(DDMMYYYY)
Posted: May 8th, 2022, 4:56 am
Hi family,
Thank you so much for your guide...
I have successfully created a variable name(Item) called DOI with sub items to automatically capture the system date with logic as stated below
PROC DOI
preproc
if demode() = 1 then
DOI = sysdate("DDMMYYYY");
endif;
Now
I have successfully created a variable name(Item) called DOB with sub items for enumerators to capture the Date of Birth in same format as
(DDMMYYY) with a logic to validate the date of birth as indicated below;
PROC DOB
numeric birthDate = A1C * 10000 + A1B * 100 + A1A;
numeric isValidDate = datevalid(birthDate);
if not isValidDate then
errmsg("Birth date - %d/%d-%d is not a valid date. Please reenter", A1A, A1B, A1C);
endif;
Now I have have created a 3rd variable(Item) called Age in complete(D1) for the enumerators to enter the complete Age of the respondent refrence the the Date caputured above.
I taught of creating a logic to actually validate the ages the enumerators captured in (D1) using the Datediff function as below;
PROC D1
postproc
if datediff(DOB, DOI, "y") <> D1 then
errmsg("Age (%d) does not match date of birth (%d)", D1, DOB)
select("Correct Age", D1, "Correct date of birth", DOI);
endif;
And it is not working.
I need clarity on how to go around this without changing the paten of the date format ( from DDMMYYYY) to (YYYYMMDD)
I attached the file for your study.
Thank you.
Sham.
Thank you so much for your guide...
I have successfully created a variable name(Item) called DOI with sub items to automatically capture the system date with logic as stated below
PROC DOI
preproc
if demode() = 1 then
DOI = sysdate("DDMMYYYY");
endif;
Now
I have successfully created a variable name(Item) called DOB with sub items for enumerators to capture the Date of Birth in same format as
(DDMMYYY) with a logic to validate the date of birth as indicated below;
PROC DOB
numeric birthDate = A1C * 10000 + A1B * 100 + A1A;
numeric isValidDate = datevalid(birthDate);
if not isValidDate then
errmsg("Birth date - %d/%d-%d is not a valid date. Please reenter", A1A, A1B, A1C);
endif;
Now I have have created a 3rd variable(Item) called Age in complete(D1) for the enumerators to enter the complete Age of the respondent refrence the the Date caputured above.
I taught of creating a logic to actually validate the ages the enumerators captured in (D1) using the Datediff function as below;
PROC D1
postproc
if datediff(DOB, DOI, "y") <> D1 then
errmsg("Age (%d) does not match date of birth (%d)", D1, DOB)
select("Correct Age", D1, "Correct date of birth", DOI);
endif;
And it is not working.
I need clarity on how to go around this without changing the paten of the date format ( from DDMMYYYY) to (YYYYMMDD)
I attached the file for your study.
Thank you.
Sham.