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

I have a numeric date with time and I need to convert just the datepart into yyyy-mm-dd format.

 

data (numeric):

RFSTDT
16DEC2020:00:00:00.000

 

want (numeric):

NEW_RFSTDT
2020-12-16

  

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

As you hinted, you need to use the datepart() function to convert a SAS datetime to a SAS date.

To display that date as you want, use the yymmddd10. format.

 

 

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

Use the DATEPART function as documented here: DATEPART 

data _null_;
  RFSTDT = '16DEC2020:00:00:00.000'dt;
  NEW_RFSTDT = datepart(RFSTDT);
  format RFSTDT datetime22.3 NEW_RFSTDT yymmddd10.;
  put _all_;
run;

You also asked the same question here: https://communities.sas.com/t5/SAS-Programming/convert-numeric-date-to-another-format/td-p/707137

and you got the same answer. Why the repeat?

ChrisNZ
Tourmaline | Level 20

As you hinted, you need to use the datepart() function to convert a SAS datetime to a SAS date.

To display that date as you want, use the yymmddd10. format.

 

 

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
  • 2 replies
  • 649 views
  • 0 likes
  • 3 in conversation