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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.