Reading in the CompuStat financial statement database, I have the following variable:
However, when I execute the following code, zero observations are identified (and I've verified in the dataset that observations should have been identified):
DATA TEST02;
Set TEST01;
If DataDate > 201231;
Run;
However, when I execute the following code based on integers using the 1/1/1960 date convention, I receive the correct number of observations:
DATA TEST02;
Set TEST01;
If DataDate > 22281;
Run;
Why is SAS considering this the 1/1/1960 convention when the format is YYMMDD8, and how do I treat this as YYMMDD8 as it is indicated in the attributes? The column attributes are identical for the original dataset and the TEST02 dataset. Thank you in advance for your assistance.
A format is for display purposes, the format is applied after the data has been read from disk.
IF and WHERE clauses interact with underlying data value.
Which makes sense, since you can change the format at any time without changing the data values in the table. Otherwise your could code would not work after such change.
If you wish to use a more readable date in your comparisons use the date literal. You need to use the the corresponding format of DATE. In your example it would be '31DEC20'd
Side note, for filtering rows it's more efficient to use WHERE instead of IF.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.