Help using Base SAS procedures

calculating age using a year and specific date

Reply
N/A
Posts: 0

calculating age using a year and specific date

I need to calculate age for a dataset, but all I have is year of birth and the date they entered the program. I need to calculate the approximate age each sample was when they entered the program based on the year of his/her birth and the date they entered the program. I just am not sure the correct program to do this. I know how to do this with two actual dates, but not from a year and a date. Thank you for any help provided.

JH
Frequent Contributor
Posts: 139

Re: calculating age using a year and specific date

With only the Birth year available your options are limited, but for estimation purposes we can make a stab at it.

SAS has "parsing" functions for date/datetime values. My example below uses the YEAR function to extract the year from the date the subject entered the program. Let me know if this is the direction that you want to go.


data _null_;

year_of_birth=1982;
program_year=year(today());

guesstimate_of_age=program_year-year_of_birth;

put _all_;
run;

Regards
D
Super Contributor
Super Contributor
Posts: 3,174

Re: calculating age using a year and specific date

The SAS language functions YEAR, MONTH, DAY (for DATE component extraction) and to assign a SAS DATE variable consider using MDY function. Check the SAS Language DOC, also using SAS Dates conference/technical papers found on the SAS support website.

Scott Barry
SBBWorks, Inc.


Suggested Google advanced search arguments, this topic / post:

using dates tutorial site:sas.com

date functions year month day mdy site:sas.com

data step programming date variables site:sas.com
Super User
Posts: 9,687

Re: calculating age using a year and specific date

Hi.
What does your data look like ? especial your age and date?
And I think the most important thing is the weight of each month you want to set.
If you want set weight of each month to 1 (i.e. everyone birth at each month has the same probability.
So It base on your prior - probability to each month.


Ksharp
Ask a Question
Discussion stats
  • 3 replies
  • 164 views
  • 0 likes
  • 4 in conversation