Your day variable is not the same in your two data sets.
Anyway, you can do like this
data have;
input id $ day;
datalines;
A 7
A 4
A 5
B 4
B 1
B 7
B 3
C 7
C 1
C 6
D 2
D 3
D 7
E 2
E 2
E 3
E 4
;
data want;
N_day=0;
do until (last.id);
set have;
by id;
if day in (1, 6, 7) then N_day=N_day+1;
end;
do until (last.id);
set have;
by id;
output;
end;
run;
Why does the count increase by 1 at this line?
B 4 2
Your day variable is not the same in your two data sets.
Anyway, you can do like this
data have;
input id $ day;
datalines;
A 7
A 4
A 5
B 4
B 1
B 7
B 3
C 7
C 1
C 6
D 2
D 3
D 7
E 2
E 2
E 3
E 4
;
data want;
N_day=0;
do until (last.id);
set have;
by id;
if day in (1, 6, 7) then N_day=N_day+1;
end;
do until (last.id);
set have;
by id;
output;
end;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: