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;
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info 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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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