Hello,
I am trying to convert converting date YYYY-MM-DDT00:00:00 to MM-DD_YYYY.
Example 2016-10-16T00:00:00 to 10162016
Code used
data date1;
set date;
newdate=input(yymmdd10.);
format newdate mmddyy10.;
run;
Thank you
If you have a true SAS datetime, you can access the date part with datepart()
and then re-format to mmddyyn8:
data have;
mydate='10NOV05:03:49:19'dt;
format mydate datetime.;
run;
data want;
set have;
newdate=datepart(mydate);
format newdate mmddyyn8.;
run;
-unison
data want;
char_date='2016-10-16T00:00:00';
want_date=input(char_date,yymmdd10.);
format want_date mmddyyn8.;
run;
data want;
set have;
want_date=input(char_date,yymmdd10.);
format want_date mmddyyn8.;
run;
Thank you for replying to my question. Unfortunately I am getting . in my new date variable. Do you have any thoughts as to what I may have done wrong?
There are many. You can help narrow the possibilities down by providing more information. What is the name of the variable you have? Is it numeric or character? Does if have a format attached to it? If so what format? Did your test code generate errors or warnings? Show the log. Make sure to copy the text from the log and use the Insert Code button on the forum editor to get a pop-up window to paste the lines of text. This will prevent the forum from reflowing the text as if it was a paragraph.
Do you have a question here?
Did the code you posted not work?
Do you want to create a numeric variable with date values (number of days)? Or another character variable?
Do you want the dates to display with the mixed hyphen and underscore delimiters as in your title? Or would you prefer to see them with some other delimiter? The MMDDYYx format lets you pick the delimiter by changing the letter X to one of: BCDPS or use N and get no delimiter at all.
Is your source variable really a character string? Or is it a datetime value with a format that makes appear in that style? If so then just use the DATEPART() function to get the number of days from the number of seconds the variable currently has.
@heatherjae15 wrote:
Hello,
I am trying to convert converting date YYYY-MM-DDT00:00:00 to MM-DD_YYYY.
Example 2016-10-16T00:00:00 to 10162016
Code used
data date1;
set date;
newdate=input(yymmdd10.);
format newdate mmddyy10.;
run;
Thank you
Is your variable date character or is it numeric with a format such as E8601T18. applied?
If character convert as @novinosrin shows.
If the variable has that E8601 (or similar ) format then the value is a DATETIME and can get the date portion with the DATEPART function:
data date1; set date; newdate= datepart(date); format newdate mmddyy10.; run;
you need to provide a character value to the INPUT function, either as a literal value or the name of the variable.
Your data step probably threw at least one error related to the syntax of the input function.
If you have a true SAS datetime, you can access the date part with datepart()
and then re-format to mmddyyn8:
data have;
mydate='10NOV05:03:49:19'dt;
format mydate datetime.;
run;
data want;
set have;
newdate=datepart(mydate);
format newdate mmddyyn8.;
run;
-unison
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.