BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6
Dear All:
 

May data is as follows

Date                         ID                  Time
22OCT2018                A                   9:00
22OCT2018                A                   9:00
22OCT2018                A                   9:01
22OCT2018                A                   9:02
22OCT2018                B                   9:08
22OCT2018                B                   9:09
22OCT2018                B                   9:10
22OCT2018                B                   9:10

I want to construct a variable that groups the ID's by time

Date                         ID                  Time             Group
22OCT2018                A                   9:00               1
22OCT2018                A                   9:00               1
22OCT2018                A                   9:01               2
22OCT2018                A                   9:02               3
22OCT2018                B                   9:08               1
22OCT2018                B                   9:09               2
22OCT2018                B                   9:10               3
22OCT2018                B                   9:10               3

 

Please Help.

 

Thanx

  Randy

1 REPLY 1
novinosrin
Tourmaline | Level 20

data have;
input Date    : date9.                      ID     $             Time :time5.;
format  date date9.   Time time5.;
cards;
22OCT2018                A                   9:00
22OCT2018                A                   9:00
22OCT2018                A                   9:01
22OCT2018                A                   9:02
22OCT2018                B                   9:08
22OCT2018                B                   9:09
22OCT2018                B                   9:10
22OCT2018                B                   9:10
;
data want;
set have;
by id time;
if first.id then group=1;
else if first.time then group+1;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 870 views
  • 3 likes
  • 2 in conversation