problem generating age

noetsi

Fortran must die
#1
I have a function I have used for years successfully to calculate age. It's

((floor ((intck('month',

T1.DATEOFBIRTH,

T1.DATEBEGIN_AT_CLO) - (day (T1.DATEBEGIN_AT_CLO) < day (T1.DATEOFBIRTH)))/12) )
)

Where I want to calculate age at datebegin_At_Clo .The problem here is that I am starting with a date stored as a text field (I did not generate it the federal government does and I do not know how they formatted it except that it is a string).

It is of the form '19761026' where the first four digits are the year, the next two the month and the next two the days.

I ran

PROC SQL;
CREATE TABLE WORK.QUERY_FOR_Q16 AS
SELECT t1.DateOfBirth,
t1.ClosureDate,
/* DOB */
(INPUT(t1.DateOfBirth, yyyymmdd10.)) LABEL="DOB" AS DOB,
/* CD */
(INPUT(t1.ClosureDate, yyyymmdd10.)) LABEL="CD" AS CD
FROM WORK.Q16 t1;
QUIT;

and it appears to generate a number fine. However when I use the new fields (DOB and CD) in the age function above I get no results (not errors just no results).

That is I get nothing when I run

PROC SQL;
CREATE TABLE WORK.QUERY_FOR_Q16_0000 AS
SELECT t1.DateOfBirth,
t1.ClosureDate,
/* Age */
(((floor ((intck('month',

T1.Dob,

T1.cd) - (day (T1.cd) < day (T1.Dob)))/12) )
)
) LABEL="Age" AS Age
FROM WORK.QUERY_FOR_Q16 t1;
QUIT;
 
Last edited:

noetsi

Fortran must die
#3
Yes it does. This was done in EG so typos like that reflect me copying wrong. The system does it automatically. I think SAS is having problems with the fact that the date is stored as 'yyyymmdd' in the original text string. As in '19761026' I converted it to a number correctly, but it does not seem to be able to make sense of that number.
 

noetsi

Fortran must die
#6
This code, followed by the age calculation, works. I am not sure why my other code failed but it does not matter.

Data TEST15b;
set work.closures2;
Dob = Input(dateofbirth, Yymmdd10.);
cd = Input(closuredate, Yymmdd10.);
Run;