Reputation: 474
I'm having trouble calling a date within an if statement. My date is, for example, "2001-08-05". I am trying to subset my data based on the date. So this is my code:
If ID = "Yes" and Date > 2001-08-05 then delete;
But this just doesn't do what I'm asking. I don't get an error, but it doesn't perform what I ask. I tried "2001-08-05"d. as well but this produced an error. Is there a certain way to read this format?
Upvotes: 1
Views: 692
Reputation: 1270411
The proper format for a date constant in SAS is 'ddmmmyyyy'd
, so:
if ID = 'Yes' and Date > '05Aug2001'd
You can use either single or double quotes to delimit the constant. The month name in the constant is case insensitive.
On a side-note, if you need to do a date-time constant in SAS, the format is 'ddmmmyyyy:hh:mm:ss'dt
. Notice the suffix becomes dt
rather than just d
and there is a semi-colon between the date and time.
Upvotes: 2
Reputation: 4554
Or you could try to covert character to date
If ID = "Yes" and Date > input('2001-08-05',yymmdd10.) then delete;
Upvotes: 2