I am having trouble calculating age from from date;
Attached is the code for someone who's birthday is 19591207
IF YEAR_TERM EQ '20144' THEN DO; v;
CCYY = YEAR(BRTHDATE_ERSS);
MM = MONTH(BRTHDATE_ERSS);
DD = DAY(BRTHDATE_ERSS);
BIRTHDATE = (CCYY*10000)+(MM*100)+DD;
IF MM LT 10 THEN AGE = 2014-CCYY;
IF MM EQ 10 THEN DO;
IF DD LE 10 THEN AGE = 2014-CCYY;
IF DD GT 10 THEN AGE = 2013-CCYY;
END;
IF MM GT 10 THEN AGE = 2013-CCYY; ;
END;
Any help would be appreciated, Patty
Sorry, I should have been more clear, the birth date above was an example of the format. I have over 20,000 dates.
I am getting the error messages with all the birth dates dates including the one mentioned above:
NOTE: Invalid argument to function YEAR(19591207) at line 9224 column 16.
NOTE: Invalid argument to function MONTH(19591207) at line 9225 column 14.
NOTE: Invalid argument to function DAY(19591207) at line 9226 column 14.
Functions like "year()" require a SAS Date value as input. A SAS Date value is the count of days since 1/1/1960. You need to convert your "dates" to a SAS Date value. See code below.
data test;
date_as_number=19591207;
date_as_SASDate_value=input(put(date_as_number,8.),yymmdd8.);
year_part=YEAR(date_as_SASDate_value);
age=yrdif(date_as_SASDate_value,today(),'age');
format date_as_SASDate_value date9.;
output;
stop;
run;
proc print data=test;
run;
The largest date value SAS currently will accept (at least in 9.2) is 6589335 corresponding to 31 Dec 20,000 (yes 5 digit year!)
Using 19591207 would be about the year 50,000.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.