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.PNGCapture.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;
The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
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.

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 3327 views
  • 7 likes
  • 5 in conversation