I apologize if this has been answered - I could not find the post I did Friday.
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 only missing data for Age 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;
Your post from friday is here
https://communities.sas.com/t5/Base-SAS-Programming/problems-with-calculating-age/m-p/350206
Several responses in
https://communities.sas.com/t5/Base-SAS-Programming/problems-with-calculating-age/m-p/350206
Note that if you click on your user name in the upper right it will bring you to a profile page with links to your most recent posts.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.