Solved
Contributor
Posts: 29

# Assign a number with ind two groups based on date information

Dear Experts

I have the following data in the three first columns and would like to assign the number in column four (meeting number). The number is based on the date. If this shifts then a new number has to be assigned. The data set includes numerus other variables.

 Record_id Admission number Date Meeting number 1 1 01-01-2001 1 1 1 01-01-2001 1 1 1 01-03-2001 2 1 2 01-05-2001 1 1 2 01-05-2001 1 1 2 01-05-2001 1

Kind regards

Solvej

Accepted Solutions
Solution
‎04-17-2018 08:10 AM
Super User
Posts: 2,041

## Re: Assign a number with ind two groups based on date information

``````data have;
infile cards expandtabs;
input Record_id	Admission 	Date : \$20.;
cards;
1	1	01-01-2001	1
1	1	01-01-2001	1
1	1	01-03-2001	2
1	2	01-05-2001	1
1	2	01-05-2001	1
1	2	01-05-2001
;
run;

data want;
set have;
k=lag(Date);
else if k ne date then meeting_number+1;
drop k;
run;``````

All Replies
Posts: 1,848

## Re: Assign a number with ind two groups based on date information

Assuming data is sorted by the 3 coloms then do:

``````data want;
set have;
retain meeting_number;

if first.date then meeting_number = 1;
else meeting_number +1;
run;``````
Super User
Posts: 6,899

## Re: Assign a number with ind two groups based on date information

I think that's in the ballpark, but you need to tweak the logic a bit:

data want;
set have;
if first.admission_number then meeting_number = 1;
else if first.date then meeting_number +1;
run;

Occasional Contributor
Posts: 5

## Re: Assign a number with ind two groups based on date information

Hi,

Try this code.

data test;
set abc;
retain hold .;
hold=date;
meeting=1;
end;
if hold ne date then do;
hold = date;
meeting + 1;
end;
run;

Super User
Posts: 10,846

## Re: Assign a number with ind two groups based on date information

``````data have;
infile cards expandtabs;
input Record_id	Admission 	Date : \$20.;
cards;
1	1	01-01-2001	1
1	1	01-01-2001	1
1	1	01-03-2001	2
1	2	01-05-2001	1
1	2	01-05-2001	1
1	2	01-05-2001
;
run;
data want;
set have;
want+first.date;
run;``````
Solution
‎04-17-2018 08:10 AM
Super User
Posts: 2,041

## Re: Assign a number with ind two groups based on date information

``````data have;
infile cards expandtabs;
input Record_id	Admission 	Date : \$20.;
cards;
1	1	01-01-2001	1
1	1	01-01-2001	1
1	1	01-03-2001	2
1	2	01-05-2001	1
1	2	01-05-2001	1
1	2	01-05-2001
;
run;

data want;
set have;
k=lag(Date);