01-03-2013 01:23 PM
I have a column called "date of first visit to the clinic" and "date of diagnosis". My imported Excel Data Sheet has them as 12 28 2004 under the date of first visit to the clinic and 02 22 2008 under the date of diagnosis. How could I calculate the elapse of time in days, weeks and months in this case?
So far, I have been able to do PROC PRINT just to make sure that my SAS is reading those data right. I have them
The SAS System 16
Obs DDT MMT YRT
1 11 18 2012
2 12 28 2011
3 2 7 2012
4 9 12 2008
5 1 30 2012
6 8 4 2000
7 7 31 2009
8 10 2 2000
I have another set that looks like this and need to figure out the elapse of time between the two sets of dates. Any advice is appreciated. I am a beginner SAS user going into the intermediate level.
01-03-2013 01:45 PM
You may try below code and see if it works for you.
sday = 28; smonth = 12; syear = 2004;
eday = 22; emonth = 2; eyear = 2008;
sdate = mdy(smonth,sday,syear);
edate = mdy(emonth,eday,eyear);
*Duration in days;
ndays = (edate-sdate) + 1;
*Duration in weeks;
nweeks = ndays/7;
*Duration in months. I defined month as 30 days duration;
nmonths = ndays/30;
format sdate edate date9.;
01-03-2013 02:03 PM
You'll need to convert the day, month and years to date values.
Then you'll need to merge the datasets together and you can subtract dates to get the difference between. Sometimes you need to add 1 to the difference depending on how you're calculating things.
02-13-2013 03:52 AM
When people say that I need to convert the day, month and years to date values, what do they mean and how do I code this on SAS? My Excel spreadsheets has these values in separate columns. I have one column for just for month, another column for date and another column for years. I am going to change so that my dates will be all in one column in the format of MMDDYYYY.
Please help with figuring out the elapse of time. I am really struggling almost over a month.
02-13-2013 10:59 AM
Use the mdy() function in SAS.
Both Nick and Linlin have posted examples.
It's equivalent to the date function in Excel but the parameters are in a different order.