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.
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!
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.