BookmarkSubscribeRSS Feed
unwanted_banana
Calcite | Level 5

HAVE: 

2017-04-20 00:00:00

 

WANT: 

2017-04-20 

AND

20/04/2017

(two separate formats for two different purposes)

5 REPLIES 5
Reeza
Super User
want1 = datepart(have);
format want1 yymmddd10.;
want2=want1;
format want2 ddmmyys10.;
want1_char = put(want1, yymmddd10.);
want2_char = put(want2, ddmmyys10.);

@unwanted_banana wrote:

HAVE: 

2017-04-20 00:00:00

 

WANT: 

2017-04-20 

AND

20/04/2017

(two separate formats for two different purposes)


 

unwanted_banana
Calcite | Level 5

Ran the code and for some reason datepart returns a null value.

Astounding
PROC Star

This will happen if HAVE is actually a character variable, not a true date/time.  In that case:

 

length want1 want2 $ 10;
want1 = have;
want2 = put(input(want1, yymmdd10.), ddmmyys10.);

 

Reeza
Super User
The log usually tells you more than that.
Kurt_Bremser
Super User

First of all, store date, time and datetime values as such; numbers that contain either the count of days or the count of seconds starting at 1960-01-01:00:00:00 or midnight (in case of pure time).

Then, whenever you need it, use the appropriate format to display the values as wanted.

In your case, this would be either YYMMDD10. or DDMMYY10.

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
  • 5 replies
  • 827 views
  • 0 likes
  • 4 in conversation