i have a variable "date" which contains dates whose formats are in $11. But i want those in format YYYY-MM-DD.how to do this?
for example the dates are like Apr 01 2019, i want it to be like 2019-04-01.
Hi @TANMOY05 Please offer the credit to @PaigeMiller whose original solution is the right one. I would like to point a very minor typo that the default length that anydtdte. informat would read is 9 bytes. I am afraid the typo needs to be corrected by specifying 11. as suffix to make it work without errors
Example
data have;
char_date='Apr 01 2019';
sas_date=input(char_date,anydtdte11.);
format sas_date date9.;
run;
numeric_date=(input(char_date,anydtdte.));
format numeric_date yymmddd10.;
Hi @TANMOY05 Please offer the credit to @PaigeMiller whose original solution is the right one. I would like to point a very minor typo that the default length that anydtdte. informat would read is 9 bytes. I am afraid the typo needs to be corrected by specifying 11. as suffix to make it work without errors
Example
data have;
char_date='Apr 01 2019';
sas_date=input(char_date,anydtdte11.);
format sas_date date9.;
run;
That's very gracious, @novinosrin ! Thank you.
However, your code has a typo as well. I think it should say
format sas_date yymmddd10.;
otherwise the stated output desired is not achieved.
Hahaha, I blame the Dunkin coffee. 🙂 or I must admit I am noticing my hair growing grey, joining the elders club .hahahahahahha
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.