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.

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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