Hello
For some reasons I can't seem to do this. How do I convert a date
DATE = '20231002' to
DATE_EXTRACTION = '02OCT2023' in SAS please?
I have tried :
DATE_EXTRACTION = put(datepart(DATE), date9.);
But I get 22AUG1960 instead of 02OCT2023
Try this
data test;
date = '20231002';
new = put(input(date, yymmdd8.), date9.);
run;
@MILKYLOVE wrote:
Hello
For some reasons I can't seem to do this. How do I convert a date
DATE = '20231002' to
DATE_EXTRACTION = '02OCT2023' in SAS please?
I have tried :
DATE_EXTRACTION = put(datepart(DATE), date9.);
But I get 22AUG1960 instead of 02OCT2023
Dates should never be character strings, they should be numbers. Numbers that represent the number of days since 01JAN1960.
Had you written this
DATE = '02OCT2023'd;
format date date9.;
you would have the correct date ... this is the way to translate dates that you understand to numerical SAS dates. Also please note that this will not work:
DATE = '20231002'd;
Lastly, when you have actual SAS dates, you do NOT need the DATEPART function; the only time you need the DATEPART function is when the value is SAS date/time values. But your value is a SAS date, not a date/time value, and DATEPART will not do meaningful things to date values.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.