- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-18-2015 11:39 AM
(1276 views)
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.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If they are all formatted as dates it won't matter:
DATA have;
infile cards dsd;
informat date mmddyy10.;
format date mmddyy10.;
INPUT date;
cards;
01/01/2012
;
data want;
set have;
date2 = date;
date3 = date;
format date2 date9. date3 yymmdd8.;
if date = date2 = date3 then match = 'yes';
run;
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.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
So you can write your conditions as DATE9 without modifying your date variables, as long as they're date variables