BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
TonyTomov
Calcite | Level 5

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
Tom
Super User Tom
Super User

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?

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

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?

TonyTomov
Calcite | Level 5
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
Tom
Super User Tom
Super User

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;
TonyTomov
Calcite | Level 5
Thanks, looks like it’s working now.
Tom
Super User Tom
Super User

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;
TonyTomov
Calcite | Level 5
Thanks, looks like it’s working.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Discussion stats
  • 6 replies
  • 1022 views
  • 0 likes
  • 2 in conversation