Date format with the specific format (30Apr2016:00:00:00)

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Date format with the specific format (30Apr2016:00:00:00)

Hi Experts

 

I need to know if there is a specific format that can write out to a file the date format as shown below... please take note of the case. 30Apr2016:00:00:00


Accepted Solutions
Solution
‎07-20-2016 08:46 AM
Super User
Super User
Posts: 7,727

Re: Date format with the specific format (30Apr2016:00:00:00)

If its not in the default list of formats, then you need to build it yourself using a picture format:

http://support.sas.com/kb/24/621.html

View solution in original post


All Replies
Super User
Super User
Posts: 7,727

Re: Date format with the specific format (30Apr2016:00:00:00)

Have you looked through the documentation:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a001263753.htm

I would think that datetime18. would work.

New Contributor
Posts: 4

Re: Date format with the specific format (30Apr2016:00:00:00)

Thanks.

I have tried so many thing enough to even think it is not possible with SAS.

 

Your suggestion does not address the case variation on month abbreviation.

30Apr2016:00:00:00

 

Does this mean its not possible with SAS?

 

Thanks.

Solution
‎07-20-2016 08:46 AM
Super User
Super User
Posts: 7,727

Re: Date format with the specific format (30Apr2016:00:00:00)

If its not in the default list of formats, then you need to build it yourself using a picture format:

http://support.sas.com/kb/24/621.html

SAS Super FREQ
Posts: 8,820

Re: Date format with the specific format (30Apr2016:00:00:00)

You can use the datetime directive with %3B to get the 3 character month with only the first letter uppercased. This worked for me for a format:
proc format;
picture LCdate
low-high='%0d%3B%Y:%0H:%0M:%0S' (datatype=datetime);
run;

cynthia
Respected Advisor
Posts: 4,138

Re: Date format with the specific format (30Apr2016:00:00:00)

[ Edited ]

From what I can see Proc Format Picture datetime directives don't allow you to specify the casing. The same is true with OOB formats.

 

It's ridiculously complicated but I believe the only way how you can define the format exactly how you want it, is by calling a function within the format. Below code does what you're asking for (if it's justified doing it this way is another question).

proc fcmp outlib=work.funcs.test;
   function my_dt(in_dt) $ 18;
      out_dt=put(in_dt,datetime18.);
      out_dt=prxchange('s/([[:alpha:]])([[:alpha:]]+)/\u\1\L\2/oi',-1,out_dt);
      return(out_dt);
   endsub;
run;

options cmplib=work.funcs;

proc format;
  value my_dt (default=18)
    other=[my_dt()]
  ;
run;

data have;
  format dt my_dt.;
  dt='30Apr2016:14:10:23'dt;
run;

proc print data=have; run;

 

New Contributor
Posts: 4

Re: Date format with the specific format (30Apr2016:00:00:00)

Thanks Patrick.

I will test this code.. Don't you think it will raise perfomance issues? 

But I really appreaciate your help.

Respected Advisor
Posts: 4,138

Re: Date format with the specific format (30Apr2016:00:00:00)

"Don't you think it will raise perfomance issues?"

 

It won't perform as good as a "normal" format as there is a RegEx string operation in the function but I wouldn't expect a "massive" impact on performance. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 498 views
  • 4 likes
  • 4 in conversation