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



hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 714 views
  • 0 likes
  • 2 in conversation