I am using a custom datetime format. I'm looking for a solution to remove "ERROR" when the format is applied and missing data exists.
data example1;
input id dttm anydtdtm.;
format dttm datetime14.;
datalines;
100 31OCT27:23:15
101
;
run;
proc format;
picture MyMSdt other='%0m/%0d/%0Y %0H:%0M' (datatype=datetime);
run;
data example2;
set example1;
format dttm MyMSdt.;
run;
proc format;
picture MyMSdt other='%0m/%0d/%0Y %0H:%0M' (datatype=datetime);
value mymsdtt .=' ' other=[mymsdt.];
run;
data example2;
set example1;
format dttm MyMSdtt.;
run;
proc format;
picture MyMSdt other='%0m/%0d/%0Y %0H:%0M' (datatype=datetime);
value mymsdtt .=' ' other=[mymsdt.];
run;
data example2;
set example1;
format dttm MyMSdtt.;
run;
@PaigeMiller Thank you so much for your solution!
You could add missing values to your format, perhaps:
proc format;
picture MyMSdt ._-.Z="Missing" other='%0m/%0d/%0Y %0H:%0M' (datatype=datetime);
run;
Or a minor change to your format definition:
proc format; picture MyMSdt low-high='%0m/%0d/%0Y %0H:%0M' (datatype=datetime); run;
Which does not attempt to apply any formatting to missing values.
More properly should use the earliest/latest SAS datetime values that are accepted but most people don't deal with dates that extreme.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.