In a data step to suppress in-formating issues we use '??' like bellow data _null_;
x='31FEB2020'; /*Invalid date*/
put x=;
y=input(x,??date9.); /*example*/
put y=;
run; Same thing when i try to implement using proc fcmp i get error. I have added the working code, please add '??' before the date formats to see the error for yourself. proc fcmp outlib=work.funcs.trial;
function create_num_date(char_date $, type $);
if upcase(strip(type))='START' then do;
DAY=IFC(COMPRESS(SCAN(char_date,1))='UN','01',COMPRESS(SCAN(char_date,1)));
MON=IFC(COMPRESS(SCAN(char_date,2))='UNK','JAN',COMPRESS(SCAN(char_date,2)));
YEAR=COMPRESS(SCAN(char_date,3));
num_date=INPUT(COMPRESS(CATX(' ',DAY,MON,YEAR)),DATE9.); /*here*/
end;
else if upcase(strip(type))='END' then do;
DAY=IFC(COMPRESS(SCAN(char_date,1))='UN','UN',COMPRESS(SCAN(char_date,1)));
MON=IFC(COMPRESS(SCAN(char_date,2))='UNK','DEC',COMPRESS(SCAN(char_date,2)));
YEAR=COMPRESS(SCAN(char_date,3));
if DAY='UN' then num_date=INTNX("MONTH",INPUT(COMPRESS(CATX(' ',MON,YEAR)),MONYY7.),0,"END"); /*here*/
else num_date=INPUT(COMPRESS(CATX(' ',DAY,MON,YEAR)),DATE9.); /*here*/
end;
return(num_date);
endsub;
run;
options cmplib=work.funcs;
/*test data*/
data _null_;
format y date9.;
x='UN FEB 2020';
put x=;
y=create_num_date(x,'start');
put y=;
y=create_num_date(x,'end');
put y=;
x='UN UNK 2020';
put x=;
y=create_num_date(x,'start');
put y=;
y=create_num_date(x,'end');
put y=;
x='15 UNK 2020';
put x=;
y=create_num_date(x,'start');
put y=;
y=create_num_date(x,'end');
put y=;
x='15 JAN 2020';
put x=;
y=create_num_date(x,'start');
put y=;
y=create_num_date(x,'end');
put y=;
x='31 FEB 2020'; /*Invalid date*/
put x=;
y=create_num_date(x,'start');
put y=;
y=create_num_date(x,'end');
put y=;
run; What I am trying to achieve is a no error from the second data step using the user created function create_num_date(). The only way I know it can be avoided is by using a "??" before the informat. How ever when I use the "??" in informat inside the procedure, I am getting errors. Requesting to suggest a better way or any way around this.
... View more