DATA Step, Macro, Functions and more

Qualifying on dates

New User
Posts: 1

Qualifying on dates

I've succesfully converted a date9. format to mmddyy10. and I'm trying to qualify in a data step where the date variable = '01/01/2012' but when I do that I get the following error: Invalid numeric data, '01/01/2012' I added a 'd' to try to get it to see it as a date and not a character string but I received this error: Invalid number conversion on '01/01/2012'd I've copied this query from Access where the dates are in this format so I'm trying to get them to match without having to change all of the hardcoded dates in my 'where' statement. How do I get the date comparison to work? I know if I left my data set formatted with date9. I could do '01JAN2012'd but I'm trying to avoid having to rewrite all of my dates.
Respected Advisor
Posts: 2,981

Re: Qualifying on dates

[ Edited ]
Posted in reply to EAAugustine77

I believe that date comparisons must be in the form of


IF DATE = '01JAN2012'd


and not


IF DATE = '01/01/2012'd


regardless of the format used for the variable.

Paige Miller
Valued Guide
Posts: 863

Re: Qualifying on dates

Posted in reply to EAAugustine77

If they are all formatted as dates it won't matter:


DATA have;
infile cards dsd;
informat date mmddyy10.;
format date mmddyy10.;
INPUT date;

data want;
set have;
date2 = date;
date3 = date;
format date2 date9. date3 yymmdd8.;
if date = date2 = date3 then match = 'yes';


if you have dates coming in as numeric or character formats you might want to change that.  If that doesn't help give an example of the data you have and what you are trying to do.



Super User
Posts: 23,662

Re: Qualifying on dates

Posted in reply to EAAugustine77
A format only controls the display value, not the underlying value. If the variable type is numeric and you can apply a date format, then you can write the comparison in date9 format, or even as the numeric SAS date.

So you can write your conditions as DATE9 without modifying your date variables, as long as they're date variables
Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation