- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello SAS Community,
I am working on a SQL and SAS data. I need to calculate age of the child from the two variables- Date of the birth of the child and the date of the last visit of the child to the clinic.
I have both these variables, but I am unable to figure out a proper syntax to get the desired results.
Please see below attachment for the sample of a child's data pulled in SQL.
I am looking to calculate the age of the child in Years, Months and Days format from the above two variables and child's BMI ( which I have already calculate (I think so). I need to plot a graph of the values to determine where children lie on the normal growth curve.
I look forward to hearing possible solutions for the problem I am facing.
Thank you,
Anu
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To help people to help you, create a simple code snippet that they can use to help you. We don't need all the data, two or three lines would be enough. Trying to find the correct format for an example for you actually took the longest.
And also, show what you have done with the intck. So, in your case it could look like this:
data have;
input PK_UNIQUE_SPCMN_ID dob :mmddyy. DT_OF_LST_VST :mmddyy.;
format dob DT_OF_LST_VST yymmdd10.;
datalines;
1 4/30/18 3/1/19
2 4/24/18 11/14/18
;;;
run;
data want;
set have;
age = intck("year", dob, DT_OF_LST_VST);
run;
If your dates are datetime, then use the function datepart(dob) to be able to use the intck function.
Fully reading your post, I see that you wanted year, months and days. There is a SAS note about this:
http://support.sas.com/kb/24/574.html
data a;
input @1 dob mmddyy10.;
/* Get the current date from operating system */
tod=today();
/* Find difference in days, months, and years between start and end dates. */
years = intck('year', dob, tod, 'c');
months = intck('month', intnx('year', dob, years, 's'), tod, 'c');
days = tod - intnx('month', dob, months + years*12, 's');
format dob tod mmddyy10.;
datalines;
01/01/1970
02/28/1992
01/01/2000
02/28/2000
02/29/2000
03/01/2000
05/10/1990
05/11/1990
05/12/1990
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think you should start there. I'm very hesitant to provide code because you haven't provided any details (and I'm not typing out your data). You don't show what you're expecting as the results or how this could be grouped - presumably you have more than one person?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your reply Reeza. I have uploaded the data. I tried INTCK(), but my syntax wasn't working. And no one around is aware of proper use of INTCK().
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To help people to help you, create a simple code snippet that they can use to help you. We don't need all the data, two or three lines would be enough. Trying to find the correct format for an example for you actually took the longest.
And also, show what you have done with the intck. So, in your case it could look like this:
data have;
input PK_UNIQUE_SPCMN_ID dob :mmddyy. DT_OF_LST_VST :mmddyy.;
format dob DT_OF_LST_VST yymmdd10.;
datalines;
1 4/30/18 3/1/19
2 4/24/18 11/14/18
;;;
run;
data want;
set have;
age = intck("year", dob, DT_OF_LST_VST);
run;
If your dates are datetime, then use the function datepart(dob) to be able to use the intck function.
Fully reading your post, I see that you wanted year, months and days. There is a SAS note about this:
http://support.sas.com/kb/24/574.html
data a;
input @1 dob mmddyy10.;
/* Get the current date from operating system */
tod=today();
/* Find difference in days, months, and years between start and end dates. */
years = intck('year', dob, tod, 'c');
months = intck('month', intnx('year', dob, years, 's'), tod, 'c');
days = tod - intnx('month', dob, months + years*12, 's');
format dob tod mmddyy10.;
datalines;
01/01/1970
02/28/1992
01/01/2000
02/28/2000
02/29/2000
03/01/2000
05/10/1990
05/11/1990
05/12/1990
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Couple of ways depending on whether you want whole years or years with decimals. Just change TODAY function for your last visit date variable.
Age1 = intck('YEAR', DOB, today(), 'C'); * Whole years. ;
Age2 = yrdif(DOB, today(),'AGE'); * Decimal years. ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@anucharbe wrote:
Hello SAS Community,
I am working on a SQL and SAS data. I need to calculate age of the child from the two variables- Date of the birth of the child and the date of the last visit of the child to the clinic.
I have both these variables, but I am unable to figure out a proper syntax to get the desired results.
Please see below attachment for the sample of a child's data pulled in SQL.
I am looking to calculate the age of the child in Years, Months and Days format from the above two variables and child's BMI ( which I have already calculate (I think so). I need to plot a graph of the values to determine where children lie on the normal growth curve.
I look forward to hearing possible solutions for the problem I am facing.
Thank you,
Anu
Have you been to this website: https://www.cdc.gov/growthcharts/computer_programs.htm
There are links to SAS programs and data files to do growth chart computations including weight for age by sex.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I had a slightly different case
I have a column of date of birth as dob, and I want to make a new column to show the age at a particular date (01/01/2004)
I used the following code
data new;
set old;
sdate=dob;
edate='01jan2004'd;
new_column = YRDIF (state, date, 'AGE');
run;
and this worked! Hope it helps someone
regards