BookmarkSubscribeRSS Feed
Marian_2127
Calcite | Level 5

Hello everybody,

I'm just trying to delete some obs - the ones that are created at the same date and hour.

There is a column "creation_time" from which I extrat the creation_hour by using

attrib

     creation_hour      length = 8      format = hour.

     ;

creation_hour = timepart(creation_time);

(That doesn't work as I expected it to because '11:47:32' becomes '12' but that is not really important for my task.)

But there is an actual problem: Even if '11:47:32' and '11:48:01' both lead to '12' the two obs still remain, if I try to delete one of them by using

proc sort nodupkey:     by creation_hour;

That means the column creation_hour actually still contains the whole information, with minutes and seconds, doesn't it?

How can I change this? I really only want the column to contain the numbers from 1-12 - is that possible? How?

Or is there a better way to do the job?

Thanks for any ideas Smiley Happy

4 REPLIES 4
ballardw
Super User

Creation_hour= hour(creation_time);

Should return just the hour.

Marian_2127
Calcite | Level 5

Thanks for the idea but unfortunately, this doesn't return the hour. Now creation_hour equals zero for all obs - without any errors or anything in the log.

andreas_lds
Jade | Level 19

Why do you apply the hour-format to creation_hour? I think the problems are a result of applying the format.

Marian_2127
Calcite | Level 5

Ah, I see.

I used the format 'hour' because with

"creation_hour = timepart(creation_time); "

without this format, the column creation_hour contained numbers from zero to 86.399 (counting the seconds).

But with the correction
"creation_hour = hour(creation_time); "

the format is indeed not necessary.

Thanks a lot to both of you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1269 views
  • 6 likes
  • 3 in conversation