I have a data set with ID in rows and months in columns, as the one shown below.
I want to create an auxiliary column that records the first value that is not zero of each line.
ID | M1 | M2 | M3 | M4 | M5 | | Auxiliary column |
1 | 0 | 0 | 8 | 8 | 7 | | 8 |
2 | 7 | 7 | 7 | . | . | | 7 |
3 | 0 | 0 | 0 | 0 | 9 | | 9 |
4 | 0 | 9 | 9 | 9 | 8 | | 9 |
5 | 1 | 1 | 1 | 1 | 1 | | 1 |
6 | 0 | 2 | 2 | 1 | 1 | | |
Currently l am using this code, but I haven't been able to get the results I am looking for. Any ideas?
data new_ops04;
set new_ops03;
array MONTHS (24) M1-M24;
RETAIN AUXILIARY_COLUMN 0;
do i=1 to 24;
IF MONTHS(i) ne 0 and AUXILIARY_COLUMN = 0 THEN
AUXILIARY_COLUMN = MONTHS(i);
end;
drop i;
run;
Thanks a lot!