Hello @wj2,
Your code works on the test dataset HAVE created below
data have;
do patientID=1 to 8;
do start_date='31AUG2020'd,'01SEP2020'd;
do generic_name='medicationA','medicationB';
do route_medication='Injection','Other';
do _n_=1 to 3*ranuni(3);
output;
end;
end;
end;
end;
end;
format start_date date9.;
run;
and the resulting WANT dataset
Obs any oral_med
1 7 4
confirms the results of these PROC FREQ steps:
proc freq data=have;
where generic_name='medicationA' & .z<start_date<'01SEP2020'd;
tables patientID;
run;
proc freq data=have;
where generic_name='medicationA' & .z<start_date<'01SEP2020'd & route_medication ne 'Injection';
tables patientID;
run;
Therefore I suspect that the WHERE condition is not suitable for your data (or vice versa). Possible reasons include case sensitivity, other spelling differences, invisible characters in the character variables, non-SAS date values (e.g. 1092020), etc. I would scrutinize one of the observations which should be selected, but aren't.
... View more