BookmarkSubscribeRSS Feed
vThanu
Calcite | Level 5

while read the data if i have an invalid date (like 31st Feb). How to identify this? 

3 REPLIES 3
Kurt_Bremser
Super User

SAS will flag invalid data (which can't be converted with the informat used) with a NOTE in the log, and set the automatic variable _ERROR_.

The value will be set to missing.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

this paper has what I believe you are asking for.

http://support.sas.com/resources/papers/proceedings13/122-2013.pdf

 

 

FreelanceReinh
Jade | Level 19

Hello @vThanu,

 

Here's a short example:

 

data test;
input d date9.;
format d date9.;
cards;
31DEC2018
.
31FEB2019
;

Thanks to the date informat used, messages in the log notify you about the invalid date in the third raw data record, but not about the missing date in the second:

NOTE: Invalid data for d in line 221 1-9.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
221        31FEB2019
d=. _ERROR_=1 _N_=3

Both will normally appear as numeric missing values in dataset TEST (displayed as a period).

 

You can modify this behavior in different ways. For example, you can

  1. Avoid the above log messages by using the "??" format modifier.
  2. Distinguish between ordinary missing values and missing values due to invalid data (by means of the INVALIDDATA= system option).
  3. Keep a character version of the raw data values (in an additional variable) in order to check what kind of invalid values you got.
options invaliddata='X';

data test;
input c $9. @1 d ??date9.;
format d date9.;
cards;
31DEC2018
.
31FEB2019
;

Now the invalid date is represented by the special missing value .X, the log is clean and character variable C is available for investigations.

 

Please see section How Invalid Data Is Handled of the INPUT statement documentation for more information.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 5573 views
  • 1 like
  • 4 in conversation