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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 613 views
  • 3 likes
  • 2 in conversation