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

I'm looking for an efficient way to convert a column that has mixed dates to YYYY-MM-DD.

Your help is aprreciated

 

Raw_Date

01 NOV 2019

01-NOV-19

 

Corrected_Date

2019-11-01

2019-11-01

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi, For your sample Raw data , date11 is a natural informat.

 

/*reading as raw data*/
data have;
input date date11.;
format date yymmdd10.;
cards;
01 NOV 2019
01-NOV-19
;
/*If it's a sas dataset*/
data have;
input date $11.;
cards;
01 NOV 2019
01-NOV-19
;

data want;
set have;
new_date=input(date,date11.);
format new_date yymmdd10.;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi, For your sample Raw data , date11 is a natural informat.

 

/*reading as raw data*/
data have;
input date date11.;
format date yymmdd10.;
cards;
01 NOV 2019
01-NOV-19
;
/*If it's a sas dataset*/
data have;
input date $11.;
cards;
01 NOV 2019
01-NOV-19
;

data want;
set have;
new_date=input(date,date11.);
format new_date yymmdd10.;
run;
r_behata
Barite | Level 11
data have;
input Raw_Date ANYDTDTE.;
Raw_Date_New=put(Raw_Date,yymmddd10.);

put Raw_Date_New =;
cards;
01 NOV 2019
01-NOV-19
;
run;

Log :

 

 Raw_Date_New=2020-11-01
 Raw_Date_New=2019-11-01

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1433 views
  • 0 likes
  • 3 in conversation