Dear Friends,
We are trying to create a three-dimensional plot of a variable – residsq - that is a function of two parameters. The two parameters are sigma_T and sigma_Z.
Essentially, the two parameters will lie on the x and y axis and residsq will lie on z-axis. The two parameters are sigma_T and sigma_Z and we want them to vary from 0.1 to 10, in increments of 0.1
Note this is not a question about plotting it is about how to generate a variable.
In addition to the two parameters, residsq is a function of three variables that form a dataset of 14,000 observations. The variables are ret, uep, and tq. These variables are clearly fixed and are constant for different permutations of sigma_T and sigma_Z.
residsq has the following form:
residsq = [ret – (1 – 0.5*(sigma_T/1.0)) *uep – ((sigma_T*sqrt(1 – 0.5^2)))/sigma_Z)*tq]^2
Our output should look like this 3 column matrix:
sigma_T sigma_Z residsq
0.1 0.1 ?
0.2 0.1 ?
0.3 0.1 .
. .
.
.
10.0 0.1
0.1 0.2
0.2 0.2
0.3 0.2
.
.
.10.0 0.2
.
.
Is there a way to do this in a data step or in proc iml?
Thanks so much for your help!
Srinivasan
Something with a pair of nested loops perhaps:
data want;
set have; /* assumes this is where the values for uep reside if not the statements like UEP = */
do sigma_T = 0.1 to 10 by 0.1;
do sigma_F = 0.1 to 10 by 0.1;
<formula goes here>
output;
end;
end;
run;
Yes. Change '[' to '(', ']' to ')', '^' to '**', and put a semicolon at the end and you have a DATA step assignment statement. Be sure to assign values to your other variables by using other assignment statements. You can use IML, but a DATA step is a tiny bit easier for something like this.
Thanks a lot Warren!
Actually, the problem is that parameters sigma_F and sigma_T are not scalar constants.
I would like each of them range from 0.1 to 10 in increments of 0.1.
That means that they can each take 100 values.
In combination, I would 100 times 100 = 10,000 values.
So essentially, I would like to create 10,000 values of the residsq vector (dimension 14,000 by 1)
I will then sum each of these 10,000 vectors to create 10,000 values of residq that correspond to each of the 10,000 combinations.
So I think a do loop would be needed.
Thanks again for your help!
Something with a pair of nested loops perhaps:
data want;
set have; /* assumes this is where the values for uep reside if not the statements like UEP = */
do sigma_T = 0.1 to 10 by 0.1;
do sigma_F = 0.1 to 10 by 0.1;
<formula goes here>
output;
end;
end;
run;
Thanks a lot Ballardw.
That worked really well.
I appreciate it.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.