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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 867 views
  • 0 likes
  • 4 in conversation