I'm trying to perform logical operation through if-then statement but since my matrix has some value sas zero it fails to perform the operation correctly
Start M_1(y);
p=13;
outarray_M=j(nrow(y),ncol(y),.);
outarray_01=j(nrow(y),ncol(y),.);
do i=14 to (nrow(y)-1);
idx= max(2,i-p+1):i;
unit= mad(y[idx,],"nmad");
outarray_M[i,]=unit;
if all(outarray_M[i,] ^= 0) then outarray_01[i+1,] = abs((y[i+1,]-median(y[idx,])))/mad(y[idx,],"nmad");
else outarray_01[i+1,]= choose(y[i+1,] =0, 0, 9999);
end;
return(outarray_01);
finish;
@pari2189 wrote:
I'm trying to perform logical operation through if-then statement but since my matrix has some value sas zero it fails to perform the operation correctly
Can you show us the SASLOG that contains the error?
There is no error but the results are incorrect.
So what I want is if it is a non-zero value perform the calculation as per the formula and if it is zero go to the choose condition. But since if-then statement returns false because some values in matrix are zero then it never performs the calculation and goes to choose condition directly.
If
mad(y[idx,],"nmad") returns 0
then you have a division by 0 which is double-plus-ungood.
I think ballardw mailed it: The MAD function will return 0 when more than half of the values are the same value.
In addition, I'd like to point out that the outarray_M matrix is not necessary in your code. Hopefully, that code is left over from a more complicated example (thanks for supplying a short module for us to view!). If not, you can use
if unit ^= 0 then...
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.