I have a SAS dataset:
+-------+-------+-------+-------+
| var_1 | var_2 | var_3 | index |
+-------+-------+-------+-------+
| 1 | 10 | 100 | 2 |
| 2 | 20 | 200 | 1 |
| 3 | 30 | 300 | 3 |
+-------+-------+-------+-------+
Now, I want to create a new variable in the same dataset, whose value in each row is from one of var_1, var_2 and var_3, using the corresponding entry in the index variable.
That is, if my output variable is var_out, then the dataset will look like:
+-------+-------+-------+-------+---------+
| var_1 | var_2 | var_3 | index | var_out |
+-------+-------+-------+-------+---------+
| 1 | 10 | 100 | 2 | 10 |
| 2 | 20 | 200 | 1 | 2 |
| 3 | 30 | 300 | 3 | 300 |
+-------+-------+-------+-------+---------+
Here, the first value of index is 2, hence var_out takes the value of var_2, i.e. 10
Is there any way I can do it, using macro variables if required?