DATA Step, Macro, Functions and more

Another date calculation SAS

Reply
New Contributor
Posts: 3

Another date calculation SAS

Hi,

 

I have this format of a birth date : 06FEB81:00:00:00 and from this I have to calculate the age of the person. How I have to format this in order to be able to use it and then what? Thanks in advance!

Super User
Posts: 7,809

Re: Another date calculation SAS

Posted in reply to Argonious

Is this value stored as character or as a SAS datetime value (numeric, with a datetime format)?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: Another date calculation SAS

Posted in reply to KurtBremser

Datetime. the informat is ANYDTDTM40.

Super User
Posts: 7,809

Re: Another date calculation SAS

Posted in reply to Argonious

Then you can use the intck function:

age_in_years = intck('dtyear',date_of_birth,datetime());
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: Another date calculation SAS

Posted in reply to KurtBremser

I have my answer! Thank you very much! I tried to use this function earlier, but was doing it wrong. Now it works fine. Thanks again!

Super User
Posts: 11,343

Re: Another date calculation SAS

Posted in reply to Argonious

Note that what you see is a pet peeve of mine, which seems to come from some defaults and/or lazy programming in some applications: storing DATE values as DATETIME. If your data, or your use, has not actual need of the time component you can reduce the variable to only date values using: Date = datepart(datetimevariable); (you could use the same variable as the result) and assign appropriate format for display.

Otherwise in the INTCK and INTNX functions when using a period like 'year' or 'month' you preface the period with 'dt' to tell SAS the value is a date time, hence the 'dtyear'

Trusted Advisor
Posts: 1,022

Re: Another date calculation SAS

Pet Peeve yes.  But ...

 

Elvis has left the building

Super User
Posts: 7,809

Re: Another date calculation SAS

On top of what @ballardw said, date values can be stored in 4-byte numeric variables, while datetimes need all 8 bytes of the default numeric length.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 7 replies
  • 123 views
  • 1 like
  • 4 in conversation