New Contributor
Posts: 3

# SAS Help! How to run some calculations...

Hi, I need help running this!

data A;

do y=1 to 300;

if y < 5 and (1<x<6) then do;

do i=1 to 7;

do while (y-i>0);

B=(1-A(y-i));

end;

end;

end;

end;

output;

run;

So, I already have values for A(y) i.e. A(1), A(2),...A(300)

E.g. if y=4 then B= (1-A(4-1))*(1-A(4-2))*(1-A(4-3))

Thanks!

Super User
Posts: 9,599

## Re: SAS Help! How to run some calculations...

Hi,

Can you post some test data in the form of a datastep, and what the output should look like.  I am not following you at all.  Where does the variable X come into this, as its not described or set anywhere?  Why the output statement at the end, its not needed.  I assume a() is an array, what does the array define?  Test data really helps.

Super User
Posts: 10,228

## Re: SAS Help! How to run some calculations...

First of all, your code yields a single error message:

ERROR 68-185: The function A is unknown, or cannot be accessed.

telling us that A() needs to be defined. Should it be an array, or is it a function defined elsewhere?

If it is a SAS array, it needs to be defined; it is also better to enclose the subscript in {}, making this more readable and clearer.

Once this is resolved, you will get a NOTE: about x being unitialized, which will cause the condition 1 < x < 6 to always be false, so your data step won't do anything at all (besides counting y to 300). B and i will stay missing in the dataset A.

So, where does x come from?

And what is the purpose of all this?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Discussion stats
• 2 replies
• 245 views
• 0 likes
• 3 in conversation