4

I am trying to display a datetime in the format yyyy-mm-dd hh:mm (e.g. 2012-12-31 23:59)

In PHP I would normally use the format YYYY-mm-dd HH:ii to get what I want. I have been looking through the SAS knowledge base and the closest I can get is E8601DTw.d which provides 2008-09-15T15:53:00 which includes seconds as well as a "T" where I'd like a space.

Is there a format to do what I'd like? If not, is there a way to create my own? I don't know that much SAS myself I'm just trying to modify an existing system. Any help is appreciated.

GadonJ
  • 41
  • 1
  • 1
  • 2
  • 1
    Agreed. Also see http://support.sas.com/kb/24/621.html which explains how to do this generally. This is pretty close to the PHP style of datetime coding, as a bonus. – Joe Sep 11 '12 at 17:19
  • Thanks guys. I was in disbelief that SAS wouldn't already have a format to do what I wanted. I guess I'll have to make my own but judging from your links it doesn't seem all that complicated. – GadonJ Sep 11 '12 at 17:33
  • I suspect a lot of SAS formats/informats are either very old (1960s language here!) or included for compatibility with certain standards (ISO, etc.) The fact that it's so easy to roll your own format means there's really little incentive for SAS to provide more custom ones. – Joe Sep 11 '12 at 19:56
  • Why was this closed? This relates to a sas format, NOT an informat. The questions are very different. Can someone please re-open! It was clearly closed by people with no concept of SAS! – Allan Bowe Nov 16 '12 at 16:07
  • GadonJ - this is the list of formats available. http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm In this case you may have to make your own as per Joe's link using Proc Format. – Allan Bowe Nov 16 '12 at 16:18

1 Answers1

4

If the standard datetime formats provided do not meet your requirements you can create a new format:

PROC FORMAT;
  picture MyMSdt other='%0Y-%0m-%0d %0H:%0M' (datatype=datetime);
RUN;

DATA TEST;
  mydatetime='25nov2009 14:44:56'dt;
  format newdt MyMSdt.;
  newdt=mydatetime;
  put mydatetime= newdt=;
RUN;

Taken from this example that you can easily customize.

JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
Paxi
  • 61
  • 4