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
... View more