Reputation: 47
I have a dataset with a column "Day" that has very specific time entries like the following. How can I transform these entries into month?
From
Day |
---|
31MAY2019:00:00:00 |
29MAY2020:00:00:00 |
30APR2021:00:00:00 |
To
Day |
---|
May 2019 |
May 2020 |
Apr 2021 |
Upvotes: 0
Views: 725
Reputation: 1103
You just need to use the datepart()
function to get extract the date from the datetime value.
data want;
format datetime datetime20. date monyy7.;
datetime = '31MAY2019:00:00:00'dt;
date = datepart(datetime);
run;
Keep in mind this doesn't add the space in between the month and year and is still a number format. If you want this as a character you can do the following:
data want;
format datetime datetime20.;
datetime = '31MAY2019:00:00:00'dt;
date = put(datepart(datetime),monname3.)||' '||put(datepart(datetime),year.);
run;
Upvotes: 1