- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Create a new variable, use the INPUT function with the YYMMDD10. informat.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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