BookmarkSubscribeRSS Feed
J_m
Calcite | Level 5 J_m
Calcite | Level 5

The matrix r is (2*t-1)*(2*t-1) but is it empty..may you help me?

Besides, I need to start the do from a negative number is this o.k.??

This is the program:

proc iml;

t=15;

a=2*t;

r=j(a-1,a-1,.);

    do i= (1-t) to (t-1);

        do j= (1-t) to (t-1);

   

   

        az1= -(j-i);

        az2= -(j-i);

        bz1= -(j-i);

        bz2= (j-i);

        cz1= (j-i);

        cz2= (j-i);

        if j<0 then z1=az1;

        z2=az2;

        if j=0 then z1=bz1;

        z2=bz2;

        if j>0 then z1=cz1;

        z2=cz2;

        r[i,j]=probnorm(z2)-probnorm(z1);

        end;

    end;

print r;

quit;

Thanks in advance.

Waiting for your reply.

4 REPLIES 4
IanWakeling
Barite | Level 11

The program gives invalid subscript errors for the matrix r, since both i and j can be zero or negative.   I suspect you need to change it to r[i+t, j+t] = ....

J_m
Calcite | Level 5 J_m
Calcite | Level 5

Thanks for your help.

I have just tried what you suggested. The matrix is now filled with numbers but they are not correct.

Why did you suggested putting (+t)?

IanWakeling
Barite | Level 11

If you declare a 29x29 matrix then you can only reference individual elements within it by using the integers 1 to 29 as row or column subscript indices.   You were trying to use -14 to +14 as the indices, so my suggestion was to shift it back to the correct range by adding 15.

Rick_SAS
SAS Super FREQ

Since we don't know what numbers are correct, you need to tell us what you expect or give an example for t=3.

The correctness of the program depends on z2 and z1. You can check their correctness with the following:

1) Outside the  loop, allocate

Lower=j(a-1,a-1,.);

Upper=j(a-1,a-1,.);

2) Within the loop, define

Lower[i+t,j+t] = z1;

Upper[i+t,j+t] = z2;

3) Print Lower and Upper after the loop.

BTW, since the normal CDF is effectively zero when z<-6 and is 1 when z>6, you can probably get by with a smaller value of t. In any case, switch from PROBNORM(z) to CDF("Normal",z), as suggested at the end of this article: Six reasons you should stop using the RANUNI function to generate random numbers - The DO Loop

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1796 views
  • 3 likes
  • 3 in conversation