I have data like:
patid startdate endday
01S1003 9/30/2008 3/16/2009
How do I find the number of days bewteen startdate and endday?
|
2
|
|
|
|
|
4
|
You can use the built-in
The signature for the function is basically:
You can see all the details in the online help for |
||
|
|
|
3
|
Days are represented in SAS as integers representing the number of days since Jan. 1, 1960 (Day Zero). So if you have your data as SAS dates, you simply subtract:
But if those mm/dd/yyyy strings are the actual data (not just formatted representations of SAS dates), you'll need to create SAS dates, e.g.:
To make it look like the original input (more or less):
There are many, many SAS informats and formats that will handle just about any representation of a date. Also lots of handy date functions for extracting, say, the day of the week from any SAS date. However, for finding distances such as months-between you only need the INTCK function described by Jay. And for adjusting dates to, say, "first day of the next quarter in a fiscal year that begins in June" or "Two weeks from the following Friday", the INTNX function does the job. Once you get the basics of SAS dates down cold, they simplify your (programming) life wonderfully. |
|||
|
|
|
1
|
Hi. I know this question has already been answered but I thought I would present this as an alternative as the original question was a little ambiguous. For example, say you wanted to calculate a person's age (the number of full years inbetween now and the day they were born). You cannot easily use intck to do this correctly. Below I have included a macro function that I use to achieve this and similar purposes... ie. how many months has a customer been with us. Have they been with us for a full year. etc... This macro function has been written in pure macro code so that it can be called from within a datastep or SQL function almost as easily as any in-built SAS function. I suggest putting it in your macro autocall library.
|
||
|
|
|
0
|
data null; sdate="12mar1998"d; edate="12jun2008"d; days=datdif(sdate,edate,'act/act'); put days; run; Sarath http://studysas.blogspot.com/2009/03/how-to-calculate-number-of-years-and.html |
||
|
|