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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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 !

View solution in original post

5 REPLIES 5
ed_sas_member
Meteorite | Level 14

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;

 

 

 

PierreYvesILY
Pyrite | Level 9

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.

ed_sas_member
Meteorite | Level 14

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 !

PierreYvesILY
Pyrite | Level 9
Thank you, I got the desired answer.
ed_sas_member
Meteorite | Level 14

Awesome !

Have a great day.

 

Best,

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1103 views
  • 2 likes
  • 2 in conversation