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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.