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

Hi SAS Experts,

I got bad data from the clients, some times the date in column X is formatted as 26.01.2016 sometimes as 2016-02-23.

How can I create a SAS date column that unify's the format into yyyy-mm-dd?

Thanks for any help.


dates.png
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Read the data into a character variable with length 10, and then input into your date variable; select the format according to the occurence of a dash in position 5.

data want;
set have (rename=(L=old_L));
format L yymmddd10.;
if substr(old_L,5,1) = '-'
then L = input(old_L,yymmdd10.);
else L = input(old_L,ddmmyy10.);
drop old_L;
run;

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try the below code


data want;
set have;
y=input(x,anydtdte10.);
format y yymmdd10.;
run;
Thanks,
Jag
Kurt_Bremser
Super User

Read the data into a character variable with length 10, and then input into your date variable; select the format according to the occurence of a dash in position 5.

data want;
set have (rename=(L=old_L));
format L yymmddd10.;
if substr(old_L,5,1) = '-'
then L = input(old_L,yymmdd10.);
else L = input(old_L,ddmmyy10.);
drop old_L;
run;
metallon
Pyrite | Level 9
Kurt, you are amazing!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 2973 views
  • 5 likes
  • 3 in conversation