BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sugita
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

5 REPLIES 5
Haikuo
Onyx | Level 15

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

Linlin
Lapis Lazuli | Level 10

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

Haikuo
Onyx | Level 15

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

Linlin
Lapis Lazuli | Level 10

Thank you Haikuo!  - Linlin

data_null__
Jade | Level 19

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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