Hello!
Can someone help me to convert a Character datetime type variable into a Date format? thanks
example:
2014-08-24 13:20:00.0000000 -04:00
I used this data step to convert character datetime to date, however it's not giving me the result I wanted.
data want; set have;
new_date=input(date_entered,anydtdtm.);
format new_date mmddyy10.;
run;
I'm getting ********* as a result.
Add the datepart() function:
data test;
date_entered = "2014-08-24 13:20:00.0000000 -04:00";
new_date = datepart(input(date_entered,anydtdtm.));
format new_date mmddyy10.;
run;
Add the datepart() function:
data test;
date_entered = "2014-08-24 13:20:00.0000000 -04:00";
new_date = datepart(input(date_entered,anydtdtm.));
format new_date mmddyy10.;
run;
thanks so much, the datepart worked.
Hello!
I am trying to convert a character date data to numeric to date. Can someone assist? thanks.
Example Data:
2015-04-07 14:35:00.0000000 -04:00
Didn't you ask this question a few days ago? You even marked the answer correct.
https://communities.sas.com/t5/SAS-Programming/Character-DateTime-to-Date/m-p/611322#M178165
I merged it back into the original thread, to keep all answers in one place.
If you just want the DATE from that sting you can use the INPUT() function with the YYMMDD10. informat to just read the first 10 characters.
Or did you instead want to generate the DATETIME value that the string represents? If so do you really need to subtract the 4 hours that the tail end seems to indicate?
647 data x; 648 string='2015-04-07 14:35:00.0000000 -04:00'; 649 date1=input(string,yymmdd10.); 650 datetime1=input(string,anydtdtm28.); 651 format date1 yymmdd10. datetime1 datetime20. ; 652 put (_all_) (=/); 653 run; string=2015-04-07 14:35:00.0000000 -04:00 date1=2015-04-07 datetime1=07APR2015:14:35:00
Thank you Tom.
HI @Eugenio211
Use yymmdd10. informat
data want;
set have;
new_date=input(date_entered,yymmdd10.);
format new_date mmddyy10.;
run;
Why did you use the INFORMAT (anydtDTM) that creates a datetime value if you wanted a date value?
Just change the informat to one that generates a date value.
data want;
set have;
new_date=input(date_entered,anydtDTE.);
format new_date mmddyy10.;
run;
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.