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

One of my SAS data set gives the date in below format(Datetime24.3)

How do I convert this to MMDDYY format?

 

Date

10Sep2015:13:39:08.000

10Sep2015:13:45:08.000

10Sep2015:15:20:08.000

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It depends on whether your original variable is a numeric SAS date, or a character string.  For a numeric SAS date:

 

date = datepart(date);

 

For a character string, a good suggestion has already been posted.  However, note that it could be simplified.  WIthin the context of that earlier suggestion:

 

date1 = input(date2, date9.);

 

Either way, apply the FORMAT statement to the resulting variable.

 

 

 

 

View solution in original post

4 REPLIES 4
DeepakSwain
Pyrite | Level 9

Hi there,

I have make a simple try. It might work for you.

data test1;
input date1 $22.;
datalines;
10Sep2015:13:39:08.000
10Sep2015:13:45:08.000
10Sep2015:15:20:08.000
;
run;


data test2;
set test1 (rename=(date1=date2));
date1=input(substr(date2, 1, 9), date9.);
format date1 MMDDYY10. ;
drop date2;
run;

 

Swain
Astounding
PROC Star

It depends on whether your original variable is a numeric SAS date, or a character string.  For a numeric SAS date:

 

date = datepart(date);

 

For a character string, a good suggestion has already been posted.  However, note that it could be simplified.  WIthin the context of that earlier suggestion:

 

date1 = input(date2, date9.);

 

Either way, apply the FORMAT statement to the resulting variable.

 

 

 

 

DeepakSwain
Pyrite | Level 9

Hi Astounding,

Based on your guidance, I have updated the sas code for numeric sas date as :

data test1;
input date1 $22.;
datalines;
10Sep2015:13:39:08.000
10Sep2015:13:45:08.000
10Sep2015:15:20:08.000
;
run;


data test2;
set test1 (rename=(date1=date2));
date3=input(date2, datetime24.3);
date1=datepart(date3);
format date1  MMDDYY10.;
drop date2 date3;
run;

Regards,

Deepak

Swain
Astounding
PROC Star

Note that you could have gone directly from date1 to date2:

 

date2 = input(date1, date9.);

 

The DATE9 informat instructs the software to reach the first 9 characters of DATE1, when calculating DATE2.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1493 views
  • 3 likes
  • 3 in conversation