BookmarkSubscribeRSS Feed
ChrisNZ
Tourmaline | Level 20
Another (quick and dirty) way is to test actual values.

3 millions gives you a date past year 9999, but a date time in feb 1960.

so unless you deal with dates going back to 1960, you can be safe assuming that

value > 3e6 means datetime

value < 3e6 means date.

If you might use 1960 or older dates, you need to use formats as seen above.
anandbillava
Fluorite | Level 6
Thanks cynthia. I used compress method instead of scan function.
I have completed my program on this. Its working fine now.
monei011
Calcite | Level 5
The problem you have is that SAS only has two data types: Character and Numeric. SAS stores dates and times as numeric data type and the fact that the value stored is a date or date time is lost unless you document that somewhere.
Assigning a format or informat is one way to document it (internally within the dataset itself) but that is prone to problems, because anyone who has write access to your dataset can change the format or informat attribute. Not ony that someone might just rename your variable and remove the format and informat.
The dictionary tables can be used to extract a lot of attibute information that can then be used programatically. If you do know the date and datetime ranges reliably (ie the data was entered under some programatic control over the values entered and not just entered as free text) then you can do some basic range testing. you could also use a number of SAS functions for extracting parts of the date or date time, and see if they conformed to the valid range of values.
You can also use the put function to write a value in a specified date or date time format as text, assign the value to a character variable and then use character manipulation functions to pull off parts of the text and compare agains a list of month names for example.

If you have no knowledge or certainty about the source of the data, and that the values of a particular variable are dates or date times, then you expose yourself to some risk in making that assumption. The risk will depend on the consequences of the error.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 17 replies
  • 32492 views
  • 2 likes
  • 8 in conversation