I'm not sure I understand what you need. So you ordered this data set so that the values ββof the count variable always go 1, 2, 3, 1, 2, 3, 1, 2, 3... Now you want to generate the group variable so that the value increments every time the variable count goes through 3?
If so, you can do something like this:
data group; set vix.macro_spy; retain group; if _N_ = 1 then group = 0; if count = 1 then group + 1; run;
This is a common template that I use. The if _N_ = 1 is executed only once, here you initialize the variables.
Operator
retain ensures that the variable retains its value from one iteration of the DATA step to the next.
source share