If thus variable contains SAS date values (count of days starting at 1960-01-01), you must use a valid date literal:
sale_date >= '01sep2019'd
Note the DATE9 format and the trailing d which makes this a date literal. Both are mandatory.
How it is displayed is controlled by the format. The underlying value is a count of days, as mentioned, and you need to use a date literal, as mentioned, to have something human-readable in the code which can be converted to the count of days by the SAS interpreter. Or you calculate yourself how many days have passed since the start of 1960 and use that raw number 😉
Hey,
Thanks for your help.
Is the 1960 date sometimes referred to Unix date?
David
No. The UNIX epoch starts in 1970.
The core of the SAS system predates UNIX (where development started in 1969) by a few years.
Hi:
To expand on @Tom 's helpful reply, here's a way to visualize how dates work in SAS data:
A date value is stored internally in a SAS data set as the number of days from the 0 date of Jan 1, 1960. Dates can be both positive and negative numbers when stored. Dates are numeric variables in SAS and ALWAYS stored internally as a number. A negative number means that the date is BEFORE Jan 1, 1960 and a positive number means that the date is AFTER Jan 1, 1960 as represented in the picture above. So -1 would be Dec 31, 1959 and -5 would be Dec 27, 1959. -3334 would be Nov 15, 1950 and -67091 would be Jul 4, 1776. Then positive numbers are the days after Jan 1, 1960. So the number 1 would represent Jan 2, 1960, the number 5 is the stored value for Jan 6, 1960 and the number 8 would be for Jan 9, 1960. Today, Nov 13, 2024, is stored as the number 23693 and Nov 15, 2024 would be stored as 23695.
If you have a date value stored as a character string, then you cannot use the character value to calculate values like age or duration. With the date value stored as a number, then simple subtraction will allow you to calculate age in days or duration in days. There are SAS functions that are designed to work specifically with SAS numeric dates, in order to advance dates to a certain point in time or calculate intervals. However, enough said about functions because those are easily found by checking out the documentation on SAS functions.
If you are testing a numeric date value in a conditional IF or WHERE statement, then you usually use a date constant in the IF or WHERE statement because, although you could use the internally stored number for date, the date constant makes the program easier to read and maintain if you use a date constant so the condition is understandable.
Hope this helps,
Cynthia
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Ready to level-up your skills? Choose your own adventure.