Hi mounikag,
You can do it using the following approach:
data x;
length subj astdt 8 inj1-inj4 $10;
infile datalines truncover;
input subj astdt yymmdd10. inj1-inj4 $;
format astdt yymmdd10.;
datalines;
101 2020-06-03 2019-07-18 2019-08-15 2019-09-10 2019-11-14
102 2019-08-07 2019-06-12 2019-07-08 2019-08-12 2019-09-30
103 2020-01-09 2019-11-13 2019-12-16 2020-01-08 2020-03-04
104 2019-12-13 2019-11-13 2019-12-16 2020-01-08 2020-03-04
105 2019-05-15 2019-05-13
106 2019-08-05 2019-07-17 2019-08-14
107 2019-08-21 2019-07-17 2019-08-14
108 2020-06-30 2020-05-27 2020-06-24 2020-07-22
;
DATA WANT;
set x;
array inj $ inj1-inj4;
array injn injn1-injn4;
no_injs_before_astdt = 0;
do i=1 to dim(inj);
injn[i] = input(inj[i],yymmdd10.);
no_injs_before_astdt + (astdt > injn[i] > .);
end;
run;
You can drop any variables you don't like to keep. Also, in your data last line you have an error, No.of injs before astdt should be equal 2, not 3.
This code essentially converts you character dates into numeric, and then loops through array elements and increments no_injs_before_astdt every time when (astdt > injn[i] > .)
Hope, this helps.
... View more