I have the dataset with Time and Interval variable as below. I would like to add a sequential ID (Indicator) with SAS based on a condition that Interval is greater than 0.1, as follows:
| Time | Interval | Indicator |
|---|---|---|
| 11:40:38 | 0.05 | . |
| 11:40:41 | 0.05 | . |
| 11:40:44 | 0.05 | . |
| 11:40:47 | 0.05 | . |
| 11:40:50 | 0.05 | . |
| 11:42:50 | 2 | 1 |
| 11:42:53 | 0.05 | 2 |
| 11:42:56 | 0.05 | 3 |
| 11:42:59 | 0.05 | 4 |
| 11:43:02 | 0.05 | 5 |
| 11:43:05 | 0.05 | 6 |
| 11:43:08 | 0.05 | 7 |
| 11:43:18 | 0.16667 | 1 |
| 11:43:21 | 0.05 | 2 |
| 11:43:24 | 0.05 | 3 |
| 11:43:27 | 0.05 | 4 |
| 11:43:30 | 0.05 | 5 |
| 11:43:33 | 0.05 | 6 |
If I use the code
`data out1; set out ;
by Time;
retain indicator;
if Interval > 0.1 then indicator=1;
indicator+1;
run;`
Indicator is not missing for the first five observations. I would like that it starts counting only when the condition is met (Interval > 0.1).
Thanks!
You can do it with a little modification:
The summuation will start after the condition
Interval>0.1has been met, because indicator is equal to missing value before that, soindicator+1would not be calculated.And you need to initial indicator as 0, not 1. If indicator is equal to 0,
indicator^=.will be satisfied andindicator+1will be calculated.