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

Hi 

I have a dataset A:
12MAR20:11:37:13

21OCT20:20:48:00

06NOV20:20:15:00

 

I want the dataset B;

03/21/2020 11:37:13

10/21/2020 20:48:00

11/06/2020 20:15:00

 

Can I do this in SAS? if yes please let me know.

 

thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

I could not find a standard form for this, so I rolled one with PROC FORMAT:

proc format;
picture mydate 
  low-high='%0d/%0m/%Y %0H:%0M:%0S' (datatype=datetime)
;
run;

data want;
input dt datetime16.;
format dt mydate.;
datalines;
12MAR20:11:37:13
21OCT20:20:48:00
06NOV20:20:15:00
;

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

If the variable is a proper datetime-variable then changing the format attached to the variable should solve the issue.

Kurt_Bremser
Super User

I could not find a standard form for this, so I rolled one with PROC FORMAT:

proc format;
picture mydate 
  low-high='%0d/%0m/%Y %0H:%0M:%0S' (datatype=datetime)
;
run;

data want;
input dt datetime16.;
format dt mydate.;
datalines;
12MAR20:11:37:13
21OCT20:20:48:00
06NOV20:20:15:00
;
Patrick
Opal | Level 21

You must be a beginner because your question lacks a lot of necessary information to really give you an answer. 

Making tons of assumptions: You've got a variable that when you look at it shows you a date in a specific datetime format. You want to change this format to something else.

If above is true: SAS stores datetime formats in a numerical variable as the count of seconds since 1/1/1960. You then just need to apply a format to such a numerical variable so it prints this number in a human readable form. The only thing you need to do to in such a case is change the format applied to the variable. 

The SAS datetime formats that are available are documented here.

 

Assuming your locale is set to US below format should work.

/*options locale=en_us;*/
data sample;
  dttm_internal_value=datetime();
  dttm_formatted=dttm_internal_value;
  format dttm_formatted nldatms.;
run;

 

...and as a semi-serious comment as a non-US person: The cost to the global economy and lives the US causes by still using MM/DD date formats and non-metric systems must be significant.