Reputation: 73
The table with date as a variable name with respect to VOL, I want to create a new variable as FLAG that IF variables having 1 pull the date of the variable name in to the FLAG column
VOL 31-Dec-10 31-Dec-11 31-Dec-12 31-Dec-13 31-Dec-14 31-Dec-15
109001 0 0 0 0 1 0
109002 0 0 1 0 0 0
109003 0 0 1 0 0 0
109004 0 0 0 1 0 0
109006 0 0 1 0 0 1
output
VOL 31-Dec-10 31-Dec-11 31-Dec-12 31-Dec-13 31-Dec-14 31-Dec-15 FLAG
109001 0 0 0 0 1 0 31-Dec-14
109002 0 0 1 0 0 0 31-Dec-12
109003 0 0 1 0 0 0 31-Dec-12
109004 0 0 0 1 0 0 31-Dec-13
109006 0 0 1 0 0 1 31-Dec-15
Upvotes: 1
Views: 101
Reputation: 1807
You want to use the vlabel()
function since those column headings don't meet standard variable name requirements and I'm assuming they're labels. Below is example code to put in a data step, but you'll have to know the actual variable names for the array declaration and replace date1--date99
with them.
array mydates (*) date1--date99;
do over mydates;
if mydates = 1 then flag = vlabel(mydates);
end;
The way this loop is written, it will leave the date of the rightmost occurrence of 1
, which seems consistent with your example in the 19006 row.
See also vname()
.
Upvotes: 4