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.
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 25. 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.