BookmarkSubscribeRSS Feed
MCT-PHD
Calcite | Level 5

Reading in the CompuStat financial statement database, I have the following variable:

MCTPHD_0-1742945110166.png

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.

1 REPLY 1
LinusH
Tourmaline | Level 20

 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.

Data never sleeps

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 642 views
  • 0 likes
  • 2 in conversation