What is the rule you are using to assign ID's? It is not apparent to me.
Emma,
Are you trying to create the data contained in the third column as defined by the comma delimiter? It appears to work just fine when I run it in Enterprise Guide. See below.
Are you running in SAS Studio? If you are running in SAS studio, make sure your data is all the way over hard against the left margin. The first byte of data needs to start in position 1 with no indentation.
Jim
@jimbarbour I think the OP wants code to generate the NEWID from the prior two variables - which is why I asked for a rule.
data have;
infile cards dsd;
input ID $ Datetime :datetime20.;* NEW_ID;
format datetime datetime20.;
cards;
AAC56,25AUG20:02:00:00,1
AAC56,27AUG20:21:00:00,2
AAC56,31AUG20:10:30:00,3
AAC56,02SEP20:20:00:00,4
AAC56,29SEP20:21:43:00,5
AAC56,29SEP20:21:43:00,5
AAC56,29SEP20:22:03:00,5
AAC56,29SEP20:23:03:00,5
AAC56,30SEP20:00:03:00,5
AAC56,30SEP20:01:03:00,5
AAC58,28SEP20:13:45:00,1
AAC58,29SEP20:15:00:00,2
AAC58,29SEP20:16:00:00,2
AAC58,29SEP20:16:00:00,2
AAC58,29SEP20:17:10:00,2
;
%let hour=1;/*Assign your interval here i.e. 1 or 2 etc*/
data want;
do until(last.id);
set have;
by id;
if first.id=1 or intck('hour',n,datetime)>&hour then new_id=sum(new_id,1);
n=datetime;
output;
end;
drop n;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.