/*** TIP 00379 ***/
Setting variable value based on value of another variable

I have a problem that I have solved using several data steps and PROC SQL.
But I am sure that there is a much easier way of doing what I want.

DATA Temp;
Input Var200203 Var200204 Var200205 VarLookUp $11.;
DataLines;
1 2 3 Var200203
5 6 7 Var200204
3 6 9 Var200205
;
RUN;

I am trying to code a variable (VarOut) that would look for the value in the
appropiate column.  In other words it must look for the value in VarLookUp and 
then go to that column and extract the appropiate value for it's row. Please 
bear in mind that I have just over 70000 records and a slow PC :)

The output should look something like:

Var200203 Var200204 Var200205 VarLookUp VarOut
1         2         3         Var200203 1
5         6         7         Var200204 6
3         6         9         Var200205 9

Solution by Harry Droogendyk Email: harry.droogendyk@cibc_NOSPAM_.com While the vname function is comparatively expensive, it's helpful here. One additional data line added to test with unexpected data. DATA Temp; Input Var200203 Var200204 Var200205 VarLookUp $11.; DataLines; 1 2 3 Var200203 5 6 7 Var200204 3 6 9 Var200205 3 6 9 Var200206 ; data done ( drop = _: ); set temp; array vars var2: ; do _i = 1 to dim(vars) until (vname(vars(_i)) = varlookup) ; end; if _i le dim(vars) then varout = vars(_i); run; proc print data=done; run; The SAS System 09:21 Thursday, July 31, 2003 1 Obs Var200203 Var200204 Var200205 VarLookUp varout 1 1 2 3 Var200203 1 2 5 6 7 Var200204 6 3 3 6 9 Var200205 9 4 3 6 9 Var200206 . /*** end of tip 00379 ***/