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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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