BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
chinna0369
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

1 REPLY 1
Ksharp
Super User
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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 252 views
  • 1 like
  • 2 in conversation