I have a dataset that has the following vars - Account_Id, Position_1123 to Position_0224 (1123 refers to Nov'23, 1223 refers to Dec'23 and so on) Each of the positions have values ., 1,2,3 I am trying to find movements in positions month-on-month beginning here with Dec'23 (Position_1223) to Feb'24 (Position_0224). Each month is compared to previous month. Logic :- 1. If current month = last month and both are not ., then 'Static' 2. If current month <> last month and both are either 1,2,3, then 'Moved' 3. If current month = . and last month was either 1,2,3, then 'Closed' 4. If current month is either 1,2,3 and last month was ., then 'New' Code:- data test; input id $ Position_1123 Position_1223 Position_0124 Position_0224; datalines; A1 1 1 1 1 A2 1 1 2 2 A3 1 2 2 2 A4 . 1 1 2 A5 2 3 3 . A6 2 2 3 3 A7 . . 1 2 run; data want; set test; format Position_mvmt $20.; array Positions {*} Position_1123 Position_1223 Position_0124 Position_0224; do i = 2 to dim(Positions); if Positions[i] = Positions[i-1] and Positions[i] in (1,2,3) then Position_mvmt = 'Static'; else if Positions[i] <> Positions[i-1] and Positions[i] in (1,2,3) and Positions[i-1] in (1,2,3) then Position_mvmt = 'Moved'; else if Positions[i] = . and Positions[i-1] in (1,2,3) then Position_mvmt = 'Closed'; else if Positions[i] in (1,2,3) and Positions[i-1] = . then Position_mvmt = 'New'; else Position_mvmt = 'Other'; end; drop i; run; Limitations:- The code above compares and prints only the last 2 variables. I want a method where it compares 1223 to 1123 and prints to Position_mvmt_1223 and then, compare 0124 to 1223 to Position_mvmt_0124 and so on
... View more