BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mmm7
Calcite | Level 5

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;
 

Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller
mmm7
Calcite | Level 5

@PaigeMiller Thank you so much for your solution!

salah1
Calcite | Level 5
data example1;
input id dttm anydtdtm.;
format dttm datetime14.;
datalines;
100 31OCT27:23:15
101
102 3
;
run;
proc format;
picture MyMSdt LOW-HIGH='%0m/%0d/%0Y %0H:%0M' (datatype=datetime)
other= "NULL";
run;
data example2;
set example1;
format dttm MyMSdt.;
run;
Quentin
Super User

You could add missing values to your format, perhaps:

 

proc format;
   picture MyMSdt ._-.Z="Missing" other='%0m/%0d/%0Y %0H:%0M' (datatype=datetime);
run;
ballardw
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1451 views
  • 7 likes
  • 5 in conversation