Question: to clarify I'm using React and Material UI. I have strings in the format of : `CAD - Canadian Dollar` and I would like to use regex to create a string that would be equivalent to `Canadian Dollar`. Essentially the everything before the `-` would need to removed, and the one blank space in front of it would need to be removed as well. Following that I would like to set some variable to be equal to that returning string.

Here is my attempt:

```
const userCurrency = 'USD - United States Dollar'

const varSetter = (e) => {
        var test1 = e.target.innerText;
        setUserCurrency(test1);
        console.log(userCurrency);

        const currencyRegex = userCurrency.match(/[^-]*$/g)

        console.log(currencyRegex);
      }

```

This returns an array `[' United States Dollar', '']`  but how do I remove the leading whitespace, and have the result as a string and not an array? Thank you!

Answer: 
There is no need to make an array for HIGHEST since there is only one variable that you would put into that array. In that case just use the variable directly instead of trying to access it indirectly via an array reference.

First let's make an actual SAS dataset out of the listing you provided.

```
data have;
  input ID (time_a time_b time_c) (:mmddyy.) result_a result_b result_c Highest ;
  format time_a time_b time_c yymmdd10.;
cards;
001 1/1/22  1/2/22   1/3/22     3       2       4        4
002 12/1/21 12/23/21 1/5/22     6       1       2        6
003 12/22/21 1/6/22  2/2/22     5       5       7        7
;

```

If you want to loop then you need two arrays. One for times and the other for the values. Then you can loop until you find which index points to the highest value and use the same index into the other array.

```
data want ;
  set have;
  array times time_a time_b time_c ;
  array results result_a result_b result_c;
  do which_one=1 to dim(results) until (not missing(highest_time));
     if results[which_one] = highest then highest_time=times[which_one];
  end;
  format highest_time yymmdd10.;
run;

```

Or you can avoid the looping by using the WHICHN() function to figure out which of three result variables is the first one that has that HIGHEST value. Then you can use that value as the index into the array of the TIME variables (which in your case have DATE instead of TIME or DATETIME values).

```
data want ;
  set have;
  which_one = whichn(highest, of result_a result_b result_c);
  array times time_a time_b time_c ;
  highest_time = times[which_one];
  format highest_time yymmdd10.;
run;

```

[![enter image description here](https://i.stack.imgur.com/3wOjF.png)](https://i.stack.imgur.com/3wOjF.png)
Your code from [this question](https://communities.sas.com/t5/SAS-Programming/doubt-in-arrays/m-p/835339#M330254) was close, you just had the assignment backwards.

Note that an array method will assign the last date in the case of duplicate high results and WHICHN will report the first date so the answers are not identical unless you modify the loop to exit after the first maximum value is found.
With the changes suggested in the answer proposed:

```
data temp2_lead_f2022;
set temp_lead_f2022;
array _day {3} daybld_a daybld_b daybld_c;
array _month {3} mthbld_a mthbld_b mthbld_c;
array _dates {3} date1_a date2_b date3_c;
array _pblev{3} pblev_a pblev_b pblev_c;

do i = 1 to 3;
_dates{i} = mdy(_month{i}, _day{i}, 1990);
end;

maxlead= max(of _pblev(*));

do i=1 to 3;
    if _pblev{i} = maxlead then  max_date=_dates(i);
end;

*Using WHICHN to identify the maximum occurence;
max_first_index=whichn(maxlead, of _pblev(*));
max_date2 = _dates(max_first_index);

drop  k;
format date1_a date2_b date3_c dob mmddyy8. ;

run;

```