BookmarkSubscribeRSS Feed
noetsi
Obsidian | Level 7

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;

 

 

3 REPLIES 3
noetsi
Obsidian | Level 7
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.
ballardw
Super User

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 735 views
  • 0 likes
  • 3 in conversation