So I have data which goes something like this
obs | date_of_service | units | CPT | ID
-----------------------------------------
1. | 11/03/2015 | 40 |xxxx6| 234
2. | 11/04/2015 | 1 |xxxx5| 234
3. | 11/11/2015 | 1 |xxxx5| 234
4. | 11/18/2015 | 1 |xxxx5| 234
5. | 11/20/2015 | 40 |xxxx6| 234
6. | 11/25/2015 | 1 |xxxx5| 234
7. | 12/02/2015 | 1 |xxxx5| 234
etc....
over many intervals for many Ids, what I need to do is sum the units for obs between the CPT xxxx6 for each interval since it is a very large dataset with many unique IDs.
ok so this is what I have now:
%MACRO lags();
%let n=1;
data out;
set in;
by id Date_of_service ;
DO _n_=&n. until (last.id);
if (id=lag&n.(id) and CPT="xxxx6") then do;
if units ne . then output;
call missing (TOTAL);
end;
if CPT="xxxx5" or CPT= "xxxx7" then TOTAL + count;
END;
run;
%MEND;
%lags
the problem is if I have two or more xxxx6 in a row without a xxxx5 or xxxx7 in between I get a null (.) value or a 0 in TOTAL column. and I'm not getting the first observation line for all of the ids with the xxxx6 cpt.