Hi there,
I have a column which is showing as character (yyyy-mm-dd) and I want to change that to mm/dd//yyyy date format, can someone please help.
Thanks,
Mike
Create a new variable, use the INPUT function with the YYMMDD10. informat.
Here's a code sample (tested) bringing the text data in yyyy-mm-dd format and putting it out in MMDDYYS10. format. Results below.
You can either create a formatted text variable (New) or a SAS date variable with a format (New2).
Jim
DATA DATE_DATA2;
Old = '2020-10-13';
New = PUT(INPUT(OLD, ANYDTDTE10.), MMDDYYS10.);
New2 = INPUT(OLD, ANYDTDTE10.);
FORMAT New2 MMDDYYS10.;
RUN;
Do you want a SAS date or a character variable for the new variable?
I generally recommend a SAS date as it offers more flexibility.
data demo;
char_date = "2020-01-01";
SAS_date1 = input(char_date, yymmdd10.);
format sas_date1 yymmdd10.;
SAS_date2 = sas_date1;
format sas_date2 mmddyyd10.;
sas_date3 = sas_date1;
format sas_date3 date9.;
date_char_new = put(sas_date1, mmddyyd10.);
run;
proc print data=demo;run;
@mlogan wrote:
Hi there,
I have a column which is showing as character (yyyy-mm-dd) and I want to change that to mm/dd//yyyy date format, can someone please help.
Thanks,
Mike
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.