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

Hi there, 

 

I need your kind help to get system date in YYYYMMDDHHMMSS format. 

 

data _null_;
export_date=put(datetime(), datetime20.);
put export_date;
run;

 

Swain
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If you want an exact match, you can roll out your own format like this

 

proc format; 
  picture dtfmt (default=30)
    other = '%Y%0m%0d%0H%0M%0S' (datatype=datetime)
  ;
run;

data _null_;
  export_date=put(datetime(), dtfmt.);
  put export_date;
run;

View solution in original post

8 REPLIES 8
AMSAS
SAS Super FREQ

Is this close enough:

 

 

data _null_;
  export_date=put(datetime(), E8601DT.);
  put export_date;
run;

See Dictionary of Formats for a list of formats 

 

PeterClemmensen
Tourmaline | Level 20

How about

 

data _null_;
export_date=put(datetime(), B8601DT.);
put export_date;
run;
DeepakSwain
Pyrite | Level 9
Date will look like 20211012134021
Swain
ballardw
Super User

@DeepakSwain wrote:
Date will look like 20211012134021

Requires custom format:

proc format;
picture mydatetime
low-high='%Y%0m%0d%0H%0M%0S' (datatype=datetime)
;
run;

data example;
   x='12Oct2021:13:40:21'dt;
   put x= mydatetime.;
run;

The directives in the Picture statement are case sensitive, the m is month, M is minutes mix them up and don't expect to understand any result. Also this is one place that you really need to use single quotes around the directives for the format, otherwise the directives get interpreted as macro calls and will throw errors. It will be up to you to make sure that the format is available in any session than needs to use this.

PeterClemmensen
Tourmaline | Level 20

@ballardw Great minds think alike 😉

PaigeMiller
Diamond | Level 26

I don't think there is a format that is exactly YYYYMMDDHHMMSS, this comes close:

 

data null;
export_date=datetime();
format export_date b8601dt20.0;
run;

If that isn't close enough, the PICTURE statement in PROC FORMAT allows you to create your own custom date/time formats that will match exactly.

--
Paige Miller
DeepakSwain
Pyrite | Level 9
e8601dt20. will return 2021-10-21T13:46:07.
I want 20211021134607.
Swain
PeterClemmensen
Tourmaline | Level 20

If you want an exact match, you can roll out your own format like this

 

proc format; 
  picture dtfmt (default=30)
    other = '%Y%0m%0d%0H%0M%0S' (datatype=datetime)
  ;
run;

data _null_;
  export_date=put(datetime(), dtfmt.);
  put export_date;
run;

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
  • 8 replies
  • 15604 views
  • 2 likes
  • 5 in conversation