06-13-2014 09:39 AM
I am trying to determine if the dates in a variable are GE a specific date value and LE another date value (in bold). I have tried variations of the below and keep getting errors. Any syntax ideas?
format start mmddyy10.;
format stop mmddyy10.;
format filing1 mmddyy10.;
if filing1 ge '01/01/2008'd and filing1 le '12/31/2009'd;
06-13-2014 10:10 AM
Haha the general syntax for a date delimiter in sas HAS TO BE
DD Mon YYYY (no spaces). Note I say Mon, meaning the character representation of the month.
05/01/2011 would HAVE to be 05Jan2001.
Sas does this because in different countries in the world, there is NOT a consistent way to format dates. Example in the US dates are in MM/DD/YYYY, however in many parts of europe it is DD/MM/YYYY.
SO the field 05/01/2011 means May 1st 2011 in the US, however it means January 5th 2011 in other parts of the world.
Hope that helps!
06-13-2014 10:21 AM
Thank you both--that worked. However, my format statements preceding the comparison statement both reference a date format of mm/dd/yyyy (format filing1 mmddyy10.. This apparently is not an issue?
06-13-2014 10:30 AM
Short answer No.
Longer answer; Do a bit more research into Dates in Sas, and the date literal (that's what you're doing when you call 'DDMonYYYY'd.
A FORMAT statement only affects the way the data is displayed, not how it is handled by the system. Remember all "dates" in sas are really numbers (they're the number of days between 1/1/1960 and your input date). Try to format one of your dates as best12. to see what I mean.
As such, you're basically telling sas "show my dates in the format mmddyyyy10.", however they're REALLY a number.
WHen you do the date literal of "01Jan2008"d you're telling sas "I DON'T KNOW the numeric value for the date January 1st 2008, so please take this input string and convert it to that number for me". Then compare THAT NUMBER against my date field, and apply my other logic.
You can format a date ANY way you want, but it doesn't change how sas "handles" the date, only how it displays it.
Hope that helps
Need further help from the community? Please ask a new question.