BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TANMOY05
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
numeric_date=(input(char_date,anydtdte.));
format numeric_date yymmddd10.;
--
Paige Miller
novinosrin
Tourmaline | Level 20

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;
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hahaha, I blame the Dunkin coffee. 🙂  or I must admit I am noticing my hair growing grey, joining the elders club .hahahahahahha

TANMOY05
Obsidian | Level 7
haha, I would give credit to both of you. Both of your solutions helped to solve my problem. Both of you are great guys. 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 750 views
  • 1 like
  • 3 in conversation