DATA Step, Macro, Functions and more

Trouble with SAS dates

Reply
Occasional Contributor
Posts: 9

Trouble with SAS dates

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;

 

 

Occasional Contributor
Posts: 9

Re: Trouble with SAS dates

I can't figure out how to edit my previous message. In the last set of code cd and DOB are both numbers, converted from the string in the original data base.
PROC Star
Posts: 547

Re: Trouble with SAS dates

Super User
Posts: 10,466

Re: Trouble with SAS dates

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.

 

Ask a Question
Discussion stats
  • 3 replies
  • 102 views
  • 0 likes
  • 3 in conversation