HAVE:
2017-04-20 00:00:00
WANT:
2017-04-20
AND
20/04/2017
(two separate formats for two different purposes)
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)
Ran the code and for some reason datepart returns a null value.
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.);
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.