Hi,
I have below data, how can I count number of missing dates within a group? Here I have provided only one id and one visit. I have large data.
here number of missing dates by id and visit are 5 (20JUL2018, 21JUL2018, 22JUL2018, 24JUL2018, 25JUL2018).
data have;
input date $1-10 id $12-15 visit $17-25;
datalines;
19JUL2018 001 Baseline
23JUL2018 001 Baseline
26JUL2018 001 Baseline
27JUL2018 001 Baseline
28JUL2018 001 Baseline
;
run;
Thanks,
Chinna
data have;
input date :date9. id $ visit $;
format date date9.;
datalines;
19JUL2018 001 Baseline
23JUL2018 001 Baseline
26JUL2018 001 Baseline
27JUL2018 001 Baseline
28JUL2018 001 Baseline
;
run;
proc sql;
create table want as
select id,visit,range(date)+1-count(distinct date) as n_miss_date
from have
group by id,visit;
quit;
data have;
input date :date9. id $ visit $;
format date date9.;
datalines;
19JUL2018 001 Baseline
23JUL2018 001 Baseline
26JUL2018 001 Baseline
27JUL2018 001 Baseline
28JUL2018 001 Baseline
;
run;
proc sql;
create table want as
select id,visit,range(date)+1-count(distinct date) as n_miss_date
from have
group by id,visit;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.