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

Hi, I would like to make such a version of this function 'mhatx1' which omits x=i from the sum i.e. computes t4 where x is not equal to i. Is there some way to use logical operators in this case? Something like temp1=x-i where x-i is not equal to 0, else . ?

start mhatx1(m,p,h,pi,e);

t4=j(m,1);                  

do x=1 to nrow(p);

i=T(1:m);

temp1=x-i;

ue=Kmod(temp1,h,pi,e)#p;

le=Kmod(temp1,h,pi,e);

t4=sum(ue)/sum(le);

end;

return (t4);

finish;

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

If I understand your quetion, there are several ways to accomplish what you are asking. The method to choose depends on whether you want to modify the computation of ue and le, or just the sums.

Here are some functions that are good to know about:

  • The REMOVE function.   You can use this function if you want to remove certain elements from temp1. For example, the zero always occurs at the x_th position, so the following statement modifies temp1 so that it contains m-1 elements:
    temp1=remove(x-i,x);  /* exclude 0 from elements */
  • The LOC function:  Although it is not necessary here, you might need to find the indices of the elements tot satisfy some criterion before you can remove them. The LOC function enables you to find the elements. For details, see Finding data that satisfy a criterion - The DO Loop

I think the REMOVE function is all you need here.

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

If I understand your quetion, there are several ways to accomplish what you are asking. The method to choose depends on whether you want to modify the computation of ue and le, or just the sums.

Here are some functions that are good to know about:

  • The REMOVE function.   You can use this function if you want to remove certain elements from temp1. For example, the zero always occurs at the x_th position, so the following statement modifies temp1 so that it contains m-1 elements:
    temp1=remove(x-i,x);  /* exclude 0 from elements */
  • The LOC function:  Although it is not necessary here, you might need to find the indices of the elements tot satisfy some criterion before you can remove them. The LOC function enables you to find the elements. For details, see Finding data that satisfy a criterion - The DO Loop

I think the REMOVE function is all you need here.

LauriN
Calcite | Level 5

Thank you! That REMOVE was what I was looking for, even though I just ended up removing t'th solutions of the inner functions ue and le from summations:

start mhatx2(m,p,h,pi,e);

t5=j(m,1);                 

do x=1 to nrow(p);

i=T(1:m);

temp1=x-i;

ue=Kmod(temp1,h,pi,e)#p;

le=Kmod(temp1,h,pi,e);

t5=(sum(ue)-ue)/(sum(le)-le);

end;

return (t5);

finish;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 848 views
  • 0 likes
  • 2 in conversation