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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.