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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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