1
votes

I have written a macro to check for invalid dates and set it to '11111111', but got an unexpected NOTE: Invalid argument to function INPUT. The reason for the note is, source data has date "0212-04-26" which is beyond the SAS dates ranging A.D. 1582 to A.D. 19,900. So now I'm looking to check for invalid date without any message`.

My Code:

  %macro chkdate(datefld=, num_date=) ;
  /* invalid date gets set to '11111111'    */
    if &datefld ne '0001-01-01' then do ;
     t_date = input(compress(&datefld, '-'), yymmdd8.) ;
       if t_date eq . then do ;
          %errors( key_desc=Invalid Date, fname=&datefld,)
          &datefld = '11111111' ;
       end;
    end;
  %mend chkdate ;

thanks

1
The num_date= argument is not used anywhere in the macro... - Dominic Comtois
@DominicComtois sorry I have modified the macro before posting it here. As the question is mainly on t_date = input(compress(&datefld, '-'), yymmdd8.) ;. - Bharath

1 Answers

2
votes

Different approaches exist...

I'd recommend reading this paper which illustrates the ? and ?? informat modifiers to be used with input().

You could, among other avenues, start by using input() with format 8. and check that it's between, for instance, 19600101 and 20250101 (or whichever numbers are appropriate), and only then do the input() with yymmdd8..

If you want to be more thorough, you could use input() with 3 substrings and check separately the year, month and day parts (using between 1960 and 2020, between 1 and 12, etc.).