BookmarkSubscribeRSS Feed
Son_Of_Krypton
Fluorite | Level 6

Date

120/04/2020

 

as above example i have wrong date in my dataset and i want code to be fail with invalid date error and mail should be sent as wrong date identified.

 

 

11 REPLIES 11
Son_Of_Krypton
Fluorite | Level 6
data _null_;
  if 0 then set test2 nobs=NOBS;
  if NOBS>1 then do;
    put "Hello";
    put "We have a problem";
    put "Error: Records not matching" NOBS ;
               
   abort abend;
  end;
  stop;
run;

i want to check for invalid date along with above conditions

Kurt_Bremser
Super User

@Son_Of_Krypton wrote:
data _null_;
  if 0 then set test2 nobs=NOBS;
  if NOBS>1 then do;
    put "Hello";
    put "We have a problem";
    put "Error: Records not matching" NOBS ;
               
   abort abend;
  end;
  stop;
run;

i want to check for invalid date along with above conditions


And the string variable possibly containing the invalid date is in dataset test2?

Son_Of_Krypton
Fluorite | Level 6
Right invalid date in test2
ballardw
Super User

Since SAS will not even come close to creating such a "date" value I have to assume that your "date" is actually a character string. The question though is whether that value is in a SAS data dataset already or a file you are attempting to read into SAS.

 

Without details I am going to assume that it is in a SAS data set.

Attempting to convert that value to a SAS date value would result in a missing a value. Unfortunately we cannot tell from the example whether your good values are supposed to be in day/month/year or month/day/year order.

data want;
   set have;
   dateval = input(date,mmddyy10.);
  /* of if the value should be in day month year order*/
   dateval = input(date,ddmmyy10.);
   format dateval date9.;
run;

This will create missing values of dateval and invalid data messages in the log.

Son_Of_Krypton
Fluorite | Level 6

i am reading excel file and that date cell in excel file with date value as 120/04/2020 and i have already converted variable to number and applied format ddmmyy10. by this it will take date as dot but i want to identify and put error.

ballardw
Super User

Show exactly how you are reading the Excel file.

And how you are setting the format.

Son_Of_Krypton
Fluorite | Level 6
PROC IMPORT OUT= work.PRACTICE1
            DATAFILE= "&file Practice.xlsx"                                         
            DBMS=XLSX REPLACE;
            RUN;

data work.PRACTICE;
set work.PRACTICE1 ;
Date=input(LOAD_DATE,ddmmyy10.);
Date ddmmyy10.;;
run;

Thats how i am reading excel file.

ballardw
Super User

@Son_Of_Krypton wrote:
PROC IMPORT OUT= work.PRACTICE1
            DATAFILE= "&file Practice.xlsx"                                         
            DBMS=XLSX REPLACE;
            RUN;

data work.PRACTICE;
set work.PRACTICE1 ;
Date=input(LOAD_DATE,ddmmyy10.);
Date ddmmyy10.;;
run;

Thats how i am reading excel file.


If Load_date is not missing and Date is missing then you have invalid data. So set a flag of such.

I suspect you have not thought through the "email" portion as it sounded like you want one email for each such error. it may be better to do:

data work.PRACTICE;
   set work.PRACTICE1 ;
   Date=input(LOAD_DATE,ddmmyy10.);
   if not missing(load_date) and missing date then DateFlag=1;
   Date ddmmyy10.;
run;

data test;
   set work.practice (where=(Dateflag=1));
run;

if there are any records in Temp then send appropriate information from the data set in an email.

PaigeMiller
Diamond | Level 26

@Son_Of_Krypton wrote:

Date

120/04/2020

 

as above example i have wrong date in my dataset and i want code to be fail with invalid date error and mail should be sent as wrong date identified.

 

 


There's no such thing as a date that begins with "120/"

 

If that is a typo, please fix it. If it's not a typo, and you actually have a date that begins with "120/", then that's what you are having problems.

--
Paige Miller
Son_Of_Krypton
Fluorite | Level 6
Right, but program needs to validate this date and send an error vai email that date is wrong correct it so person who sent me file will fix it from his end

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 11 replies
  • 1272 views
  • 0 likes
  • 4 in conversation