Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to calculate age in years ? 2

Status
Not open for further replies.

irinnew

Technical User
Mar 19, 2005
81
US
Hi,

I am trying to calculate an age (in years)for each member substracting from System date using the following code:

DATA AgeCalc;
set base;
age=intck('YEAR',SYSDATE,mem_DOB);
run;
*****************************************************
MEM_DOB column numeric data look like the following :
13FEB1930
I got an empty age column and my log says:
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
520:27
NOTE: Variable SYSDATE9 is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing

values.
Each place is given by: (Number of times) at (Line):(Column).
62060 at 520:5
NOTE: There were 62060 observations read from the data set WORK.BASE.
NOTE: The data set WORK.AGECALC has 62060 observations and 12 variables.
NOTE: DATA statement used:
real time 1.98 seconds
cpu time 0.07 seconds


What I am doing wrong?

Thank you in advance!
Irin
 
Irin,
I am not sure where you are getting the var sysdate from. If you want to get today's system date why not use the date() function?
I would also switch the order as you will get neg ages with the way you have set up the inck function.

ex.
Code:
DATA AgeCalc;
  set base;
  age = intck('YEAR',mem_dob,DATE());
run;

One last thing, make sure that your dates (mem_dob) are in a numeric var. (I wasn't sure if that was the case from your error description.)
Klaz
 
Also, INTCK bears careful research before using it, there are cases where it can give you slightly dodgy answers. I think with INTCK using year, it will count the nmber of 01Jan dates that come up between the two dates... should give you the right answer though I think. I occasionally use a slightly different algorithm:-
Code:
   age = (date() - DOB)/365.25 ;
This will give you an age with decimal places so that you can work out if someone is 45.75 years old etc.
 
Here's an example of why I'm wary of using INTCK.
Run this code:-
Code:
data _null_;
  dob   = '15DEC2004'd;
  today = '03JAN2005'd;

  age = intck('YEAR',dob,today);
  put age=;
run;
Common sense says that the age of someone born on 15th of December as of the 3rd of January is about 3 weeks, using INTCK to get how many years old someone is, will give an answer of 1 in this case. Basically INTCK give the number of new intervals that have started between the two dates, either how many Mondays, 1st of the months or 1st of Januarys have occured, depending on whether you've specified WEEK, MONTH or YEAR respectively.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top