Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-14-2023 12:15 PM
(1496 views)

Hi everyone,

I have ran into some issues as I thought the code below was working in taking taking the maximum absolute values, however, today I discovered that it only takes the maximum of positive values and I am trying to make it work for the negative values too.

Here's the code:

data mydata;

set want;

array my_array (*) &min_num_vars2. - &max_num_vars2.;

do i = 1 to dim(my_array);

if my_array(i) = 1 then

my_array(i) = '.';

end;

drop i;

run;

data lib.data /*(keep = _NAME_ WoE_Corr)*/;

set work.mydata;

abs_sum = sum(abs(&min_num_vars2. - &max_num_vars2.));

/*WoE_Corr1 = max( of &min_num_vars2. - &max_num_vars2.)*/;

WoE_Corr2= max(abs( of &min_num_vars2. - &max_num_vars2.));

run;

The 1st WoE code in the /**/ works but it seems like it only does so for the positive values.

The 2nd WoE doesn't work when I try to take the max of the absolute values in the array.

Any idea as to how to take the max of abs of an array? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

This statement makes no sense:

`if my_array(i) = 1 then my_array(i) = '.';`

Does the array contain NUMERIC variables? That is what the comparison in the IF condition is looking for. Or does it contain CHARACTER variables? That is what the assignment statement is doing.

And why would you convert ones into missing anyway? What possible meaning do these variables have where you want to treat a valid number like 1 as if it was an invalid number?

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

This statement makes no sense:

`if my_array(i) = 1 then my_array(i) = '.';`

Does the array contain NUMERIC variables? That is what the comparison in the IF condition is looking for. Or does it contain CHARACTER variables? That is what the assignment statement is doing.

And why would you convert ones into missing anyway? What possible meaning do these variables have where you want to treat a valid number like 1 as if it was an invalid number?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Its because I’m doing a Pearson correlation on WoEs where I need to find the max values but because it’s matrix, I need to remove the 1s

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Its not a matrix, it is a dataset.

So you want to eliminate the diagonal of the "matrix".

That will be when the observation number matches the column number.

```
data want;
set have;
array list ..... ;
max=.;
do col=1 to dim(list);
if col ne _n_ then max=max(max,abs(list[col]));
end;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks, looks like it’s working now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The ABS() function does not take multiple input values.

What would that even mean? Which of multiple values would it return?

If you want to find the maximum absolute value for a bunch of values then you need to call ABS() for each value separately.

```
max=.;
do i=1 to dim(list);
max=max(max,abs(list[i]));
end;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks, looks like it’s working.

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

Upcoming Events

- VALSUG User Group Meeting | 07-Nov-2024
- Ask the Expert: How Do I Perform Customer Segmentation With SAS Intelligent Decisioning? | 12-Nov-2024
- Ask the Expert: How Do I Perform Customer Segmentation With SAS Intelligent Decisioning? | 12-Nov-2024
- Club SAS de Quebec | 13-Nov-2024
- Hands-on Workshop: SAS® Viya® Workbench (at SAS Headquarters) | 13-Nov-2024
- SAS Bowl XLV, SAS Visual Analytics | 13-Nov-2024
- Ask the Expert: Leveraging R for Statistical Analysis in LSAF | 19-Nov-2024

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.