BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anucharbe
Fluorite | Level 6

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
heffo
Pyrite | Level 9

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;

 

View solution in original post

10 REPLIES 10
Reeza
Super User
Have you looked at INTCK().

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?
anucharbe
Fluorite | Level 6

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(). 

Reeza
Super User
Show the code you tried then and expected output.
heffo
Pyrite | Level 9

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;

 

SASKiwi
PROC Star

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
Fluorite | Level 6
Thanks SASKiwi. The code was very helpful. 🙂
Reeza
Super User
If you have date times you can also just modify the interval/first parameter instead of converting.
ballardw
Super User

@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.

 

anucharbe
Fluorite | Level 6
Hi BallardDW, I have looked at the CDC's SAS Program, it was little too complicated to start with since my variables needed some formatting. Thanks for the link though, i may use it for plotting and comparing results with my hypothesis. Cheers.
Gopi2
Fluorite | Level 6

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 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 28502 views
  • 7 likes
  • 6 in conversation