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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 31155 views
  • 2 likes
  • 8 in conversation