Hi Team, I am looking for a SAS code for validating a csv file. I have variables like FORMAT STARTED_TS MDYAMPM.; format yearmonth 8.; format APP_ID $255.; format SN_NUMBER 22.; format SN_AMOUNT 20.2; format P_ID 19.; Want to keep all exceptional records in a separate dataset. Thanks in advance Kajal I tried code but didn't work data work.cleandata(keep= APP_ID SN_NUMBER SN_AMOUNT P_ID)
work.errors(keep=Err_Message Faulty_Record)
;
length
APP_ID $255 SN_NUMBER 8 SN_AMOUNT 8 P_ID 8 Err_Message $ 100 Faulty_Record $ 250 ;
infile "/home/sas/score.csv " filename = _filename
delimiter = ","
dsd
truncover
missover dsd
lrecl=32767
firstobs=2;
input;
APP_ID = scan(_filename,2, ',');
SN_NUMBER = input(scan(_filename,3, ','), ?? best.);
SN_AMOUNT = input(scan(_filename,5, ','), ?? best.);
P_ID = input(scan(_filename,6, ','), ?? best.);
if missing(APP_ID) then do;
Faulty_Record = _filename;
Err_Message = 'APP_ID variable cannot be missing';
output work.errors;
end;
if missing(SN_NUMBER) then do;
Faulty_Record = _filename;
Err_Message = 'SN_NUMBER variable cannot be missing';
output work.errors;
end;
if missing(P_ID) then do;
Faulty_Record = _filename;
Err_Message = 'P_ID variable cannot be missing';
output work.errors;
end;
if missing(Faulty_Record) then do;
output work.cleandata;
end;
run;
... View more