Desktop productivity for business analysts and programmers

How to remove am pm from timestamp?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

How to remove am pm from timestamp?

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.


Accepted Solutions
Solution
‎05-21-2012 11:25 PM
Super Contributor
Posts: 1,636

Re: How to remove am pm from timestamp?

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

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: How to remove am pm from timestamp?

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

Solution
‎05-21-2012 11:25 PM
Super Contributor
Posts: 1,636

Re: How to remove am pm from timestamp?

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

Respected Advisor
Posts: 3,156

Re: How to remove am pm from timestamp?

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

Super Contributor
Posts: 1,636

Re: How to remove am pm from timestamp?

Thank you Haikuo!  - Linlin

Respected Advisor
Posts: 3,786

Re: How to remove am pm from timestamp?

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 463 views
  • 0 likes
  • 4 in conversation