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.
Please post the code in which you want to detect the invalid date string.
Use the "little running man button" to post the code.
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
@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?
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.
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.
Show exactly how you are reading the Excel file.
And how you are setting the format.
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.
@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.
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: