DATA Step, Macro, Functions and more

How to delete observations with same hour

Reply
Occasional Contributor
Posts: 9

How to delete observations with same hour

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

Super User
Posts: 10,466

Re: How to delete observations with same hour

Creation_hour= hour(creation_time);

Should return just the hour.

Occasional Contributor
Posts: 9

Re: How to delete observations with same hour

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.

Super Contributor
Posts: 259

Re: How to delete observations with same hour

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

Occasional Contributor
Posts: 9

Re: How to delete observations with same hour

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!

Ask a Question
Discussion stats
  • 4 replies
  • 183 views
  • 6 likes
  • 3 in conversation