dear SAS experts,
I have very ofter the same problem: I need to change the format of a date for another, and it is always sourec of many dificulties.
I want to change the following : 07MAR1996:00:00:00 (format is DATETIME20.)
into : 07.03.1996 (format : ddmmyyp10.)
how should I proceed?
thanks in advance,
regards
I suggest that you try the datepart() function as follows :
data have;
input date DATETIME20.;
format date DATETIME20.;
cards;
07MAR1996:00:00:00
;
run;
data want;
set have;
format date2 ddmmyyp10.;
date2 = datepart(date);
run;
Hope this help !
Dear @PierreYvesILY ,
You can do it in a data step or in a proc datasets
data mytable;
set mytable;
format date ddmmyyp10.; /* specify the variable name and the desired format*/
run;
or
proc datasets library=work;
modify mytable ;
format date ddmmyyp10.; /* specify the variable name and the desired format*/
quit;
I already tried the first solution, and it doesn't work, thus my question.
I guess the problem comes from the 0:00:00 after the date. The problem seems to convert the datetime into a date, then applying the format is easy.
I suggest that you try the datepart() function as follows :
data have;
input date DATETIME20.;
format date DATETIME20.;
cards;
07MAR1996:00:00:00
;
run;
data want;
set have;
format date2 ddmmyyp10.;
date2 = datepart(date);
run;
Hope this help !
Awesome !
Have a great day.
Best,
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.