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;
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.