How to keep a number of records based on values of another variable in SAS

  Kiến thức lập trình

I have the following data
enter image description here

I need to subset and only keep the number of records based on Total.
Thus: for ABC, only two rows will be kept (since Total=2), and keep the records whose Count=1 and 2 (no matter missing or not). So the count=3 will not be selected.

For LMN, only 3 records will be kept (since Total=3), and keep the records whose Count=1 and 2 and 3 (no matter missing or not). So the count=4 will not be selected.

The output should be like:

ABC     2        1       .
ABC     2        2     00:00
LMN     3      1      02:25
LMN     3      3      04:45
LMN     3      2      07:45

I tried to use array, if then, do loops. But really a mess, I have no functional code.
Here are the data contents:
ID Total Count Time
ABC 2 1 .
ABC 2 2 00:00
ABC 2 3 .
LMN 3 1 02:25
LMN 3 4 .
LMN 3 3 04:45
LMN 3 2 07:45

Please help, Thank you!

LEAVE A COMMENT