Raven
Raven

Reputation: 859

Do Loop and Count

I have a dataset which look like this:

   Patient_MRN         DOV1_1         DOV2_1      DOV2_2       DOV2_3     DOV2_4 ... DOV2_200
   234532            01/16/2018     08/09/2018
   232536            01/01/2018     05/07/2018    06/07/2018   09/13/2019

I would like to count the number of times the DOV2_ variable falls within one calendar year of the DOV1_1 variable by Patient_MRN. So for example, the count for patient '234532' would be 1 and patient '232536' the count would be 2 (05/07/2018, 06/07/2018).

Not sure if this is the most efficient way but option I could use to do this is to subtract the DOV2_ variables from DOV1_1, and keep then keep only the outputs that are less than 365, and then create a count of the variables that are less than 365.

To do this, I know I need to create some sort of doop loop or marco but I'm not quite sure where to begin

Upvotes: 0

Views: 233

Answers (1)

Richard
Richard

Reputation: 27498

The INTCK function can count date and time intervals. The DATA Step ARRAY statement allows you to reference variables in an array like manner;

Presume 'within one calendar year' means the interval from DOV1_1 date to next date < 1 year forward. INTCK with a 'YEAR' interval and 'C'ontinuous method will return 0 when a date is within 1 year forward.

data want;
  set have;
  array dates dov2_1-dov2_200;
  count = 0;
  do index = 1 to dim(dates);
    if intck('year', dov1_1, dates(index), 'C') = 0 then count + 1;
  end;
run;

Upvotes: 1

Related Questions