BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thesasuser
Lapis Lazuli | Level 10

The following code for outputing the date in uts format gives the data of Jan 1, 1960 instead of current date.

If keep the format as say date9. I get the correct value.

DATA createdates;
  current1= date();
  format current1  b8601dt.;
RUN;

PROC PRINT data=createdates;
  title 'The createdates data set';
  var current1  ;
RUN;:

The output is

The createdates data set 13:25 Wednesday, June 7, 2017 1

Obs current1

1 19600101T054937

 

Can anybody help?

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

change it to

 

DATA createdates;
  current1= datetime();
  format current1  b8601dt.;
RUN;

View solution in original post

5 REPLIES 5
collinelliot
Barite | Level 11

Looks like you're applying a datetime format to a date value.

kiranv_
Rhodochrosite | Level 12

change it to

 

DATA createdates;
  current1= datetime();
  format current1  b8601dt.;
RUN;
thesasuser
Lapis Lazuli | Level 10

Thanks
it worked

 The createdates data set                     13:58 Wednesday, June 7, 2017   1

                                                       Obs       current1

                                                        1     20170607T135842

 

I there a way can remove the T and have the values like "20170607135842".

The idea is to have it in YYYYMMDDHHmmSS?

kiranv_
Rhodochrosite | Level 12

you may to have to use proc format  with picture statement as shown below

PROC FORMAT;
  picture dt other='%0Y-%0m-%0d%0H%0M%0S' (datatype=datetime);
RUN;
DATA createdates;
  current1= put(datetime(),dt.);
 
RUN;

.

 

thesasuser
Lapis Lazuli | Level 10

Thanks Kiran.

I appreciate your time and efforts in replying to me and reminding that datetime is the proper format to use.

My objective was to get date in the format YYYYMMDDHHmmSS.

So the last solution is not what I want.

I had to remove T from the output. So I used this. compress(put(datetime(),b8601dt.),'T');

For comparison I ran your and my solution

 

PROC FORMAT;
picture dt other='%0Y-%0m-%0d%0H%0M%0S' (datatype=datetime);
RUN;
DATA createdates;
current1= put(datetime(), dt.);
todays_date=compress(put(datetime(),b8601dt.),'T');
RUN;

and got the result as follows

 

current1 =    2017-06-07215453

todays_date= 20170607215454

There could be many other ways to do ,

I am accepting your earlier post as a solution. It put the ray of light  on the solution

Thanks once again.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 5 replies
  • 9748 views
  • 3 likes
  • 3 in conversation