So I import a csv file where one column contains a timestamp data and I need to remove the AM/PM from 01/01/2012 13:13PM?
Please help me?
Thank you.
data have;
input dt $&20.;
cards;
01/01/2012 13:13PM
01/01/2012 10:13AM
;
data want;
set have;
dt=compress(dt,'PMAM');
proc print;run;
Obs dt
1 01/01/2012 13:13
2 01/01/2012 10:13
Hi,
This could help with the conversion:
data have;
input dt $&20.;
dt=prxchange('s/AM|PM//',-1,dt);
cards;
01/01/2012 13:13PM
01/01/2012 10:13AM
;
proc print;run;
Haikuo
data have;
input dt $&20.;
cards;
01/01/2012 13:13PM
01/01/2012 10:13AM
;
data want;
set have;
dt=compress(dt,'PMAM');
proc print;run;
Obs dt
1 01/01/2012 13:13
2 01/01/2012 10:13
Linlin,
Obviously your solution works in this context perfectly. However, on a side note:
1. 'P', 'A' and 'M' will be all be removed regardless their order and combinations, as compress() is letter based instead of string based.
2. By the same token, you only need to address 'M' one time: dt=compress(dt,'PMA');
Regards,
Haikuo
Thank you Haikuo! - Linlin
1) I think the correct answer is: change the format.
Your question does not provided enough information about what you have. When you IMPORTED the field from CSV did you end up with SAS DATE TIME value? If so then see 1.
If not, you need to read the text field into a SAS DATE TIME variable and then see 1.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.