BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DocMartin
Quartz | Level 8

I've got a datetime variable called admit that is in the datetime16. format. Example: 31JUL20:23:59:35

But I hate that formatting when I'm trying to read the results of a PROC PRINT.

Here's how I'd like the above value to appear in my output:   JUL/31/2020_23:59:35

Is there a way I can write a customized datetime format to do that?

 

Thanks!

 

Andrew

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@DocMartin wrote:

I've got a datetime variable called admit that is in the datetime16. format. Example: 31JUL20:23:59:35

But I hate that formatting when I'm trying to read the results of a PROC PRINT.

Here's how I'd like the above value to appear in my output:   JUL/31/2020_23:59:35

Is there a way I can write a customized datetime format to do that?

 

Thanks!

 

Andrew


If your really want that appearance:

proc format;
picture mydatetime
low-high='%3B/%0d/%Y_%H:%0m:%0s'  (datatype=datetime)
;
run;

data example;
   x= "31JUL20:23:59:35"dt;
   put x=mydatetime.;
run;

You will have to make sure the format is available in any session you want to use it.

 

The Picture statement is one of the few where single and double quotes make a difference. If you use double quotes in the picture then SAS will think the %(value) are macro related and not Picture statement date, datetime or time directives.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You can create a custom PICTURE format that will look exactly the way you want it to look. Here's the documentation: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=proc&docsetTarget=p0n990v...

 

And a small example: https://sasnrd.com/sas-date-datetime-proc-format-example/

--
Paige Miller
ballardw
Super User

@DocMartin wrote:

I've got a datetime variable called admit that is in the datetime16. format. Example: 31JUL20:23:59:35

But I hate that formatting when I'm trying to read the results of a PROC PRINT.

Here's how I'd like the above value to appear in my output:   JUL/31/2020_23:59:35

Is there a way I can write a customized datetime format to do that?

 

Thanks!

 

Andrew


If your really want that appearance:

proc format;
picture mydatetime
low-high='%3B/%0d/%Y_%H:%0m:%0s'  (datatype=datetime)
;
run;

data example;
   x= "31JUL20:23:59:35"dt;
   put x=mydatetime.;
run;

You will have to make sure the format is available in any session you want to use it.

 

The Picture statement is one of the few where single and double quotes make a difference. If you use double quotes in the picture then SAS will think the %(value) are macro related and not Picture statement date, datetime or time directives.

jimbarbour
Meteorite | Level 14

If you want something "quick and dirty," you can always do something like:

%LET	Dt	=	%SYSFUNC(PUTN('31JUL20:23:59:35'dt, datetime19.));
%LET	Dt	=	%QSUBSTR(&DT,3,3)/%QSUBSTR(&DT,1,2)/%QSUBSTR(&Dt,6,4)_%QSUBSTR(&Dt,11,2):%QSUBSTR(&Dt,14,2):%QSUBSTR(&Dt,17,2);
%PUT	NOTE:  &=Dt;

I some times will use something like that for a Title statement when it's a custom request and it's not something I see a lot of repeated use for.

 

Jim

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
  • 3 replies
  • 590 views
  • 4 likes
  • 4 in conversation