BookmarkSubscribeRSS Feed
r3570
Obsidian | Level 7

Hi Team,

 

I have a date column which is in character format as below:

 

Start Date
2020-02-02T16:29:00
2020-11-03
-----T12:47:00

 

I would like to convert into numeric format as well as the complete date as below:

Start Date
2020-02-02T16:29:00
2020-11-03T00:00:00
2020-01-01T12:47:00

 

Can anyone help ?

 

1 REPLY 1
yabwon
Amethyst | Level 16

Something like this:

data want;
input Start_Date $ 20.;

t1 = scan(Start_Date,1,"T");
t2 = scan(Start_Date,2,"T");

Start_Date = catx("T",
ifc(t1 = "-----","2020-01-01",t1),
coalescec(t2,"00:00:00")
)
;
drop t:;
cards;
2020-02-02T16:29:00
2020-11-03
-----T12:47:00
;
run;
proc print;
run;

?

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 765 views
  • 0 likes
  • 2 in conversation