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
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;
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().
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;
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. ;
@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.
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
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.