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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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