- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
My dataset looks like this. I have an array named da that contains 5 variables, and i want to retrieve a value of variable name from array, based on variable value(varname variable) and return probability(prob).
For example,
For the first row, the probability for variable da1 variable is 0.1.
For the second row, the probability for variable da10 variable is 0.
For the third row, the probability for variable da5 variable is 0.9.
Id | da1 | da2 | da3 | da5 | da10 | varname | prob |
1 | 0.1 | 0.2 | 0.5 | 0.15 | 0.15 | da1 | 0.1 |
2 | 0.2 | 0.6 | 0.1 | 0.1 | 0 | da10 | 0 |
3 | 0 | 0 | 0.1 | 0.9 | 0 | da5 | 0.9 |
Thank you,
Alexey
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the VVALUEX() function.
prob = vvaluex(varname);
Small catch - it returns a character value, the formatted displayed value, by default so you'll need to convert it to numeric if required.
@AlexeyS wrote:
Hi,
My dataset looks like this. I have an array named da that contains 5 variables, and i want to retrieve a value of variable name from array, based on variable value(varname variable) and return probability(prob).
For example,
For the first row, the probability for variable da1 variable is 0.1.
For the second row, the probability for variable da10 variable is 0.
For the third row, the probability for variable da5 variable is 0.9.
Id da1 da2 da3 da5 da10 varname prob 1 0.1 0.2 0.5 0.15 0.15 da1 0.1 2 0.2 0.6 0.1 0.1 0 da10 0 3 0 0 0.1 0.9 0 da5 0.9
Thank you,
Alexey
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the VVALUEX() function.
prob = vvaluex(varname);
Small catch - it returns a character value, the formatted displayed value, by default so you'll need to convert it to numeric if required.
@AlexeyS wrote:
Hi,
My dataset looks like this. I have an array named da that contains 5 variables, and i want to retrieve a value of variable name from array, based on variable value(varname variable) and return probability(prob).
For example,
For the first row, the probability for variable da1 variable is 0.1.
For the second row, the probability for variable da10 variable is 0.
For the third row, the probability for variable da5 variable is 0.9.
Id da1 da2 da3 da5 da10 varname prob 1 0.1 0.2 0.5 0.15 0.15 da1 0.1 2 0.2 0.6 0.1 0.1 0 da10 0 3 0 0 0.1 0.9 0 da5 0.9
Thank you,
Alexey
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
VVALUEX() will work, but it returns the formatted value, so the result is always character.
If you want a numeric result you could use the INPUT() function, but you might lose some precision.
prob=input(vvaluex(varname),32.);
To get the actual value you might need to scan an array.
array da da1-da3 da5 da10 ;
prob=.;
do index=1 to dim(da) while (prob=.);
if upcase(vname(da[index]))=upcase(varname) then prob=da[index];
end;
drop index;
array.