Hello SAS communities!
I am trying to create a new column and the simple example is shown below...
have data:
ID | ColA | ColB | ColC | What_Col |
1 | A1 | B1 | C1 | ColA |
2 | A2 | B2 | C2 | ColB |
3 | A3 | . | C3 | ColA |
4 | . | B4 | C4 | ColC |
Want Data:
ID | ColA | ColB | ColC | What_Col | Value_Col |
1 | A1 | B1 | C1 | ColA | A1 |
2 | A2 | B2 | C2 | ColB | B2 |
3 | A3 | . | C3 | ColA | A3 |
4 | . | B4 | C4 | ColC | C4 |
What_Col is the variable that directs which column to search.
Value_Col is the variable I would like to create that will retrieve the value from the column What_Col specifies.
I tried to write a SAS code as below but it does not work.
proc sql noprint;
select What_col into col_list separated by ',';
from have;
data want;
set have;
count+1;
do i=1 to 4;
Value_col=resolve(scan("col_list",i,',');
end;
run;
Any recommendations or advices are welcome!
Thanks in advance.