How to create a variable as a function of 2 parameters and three other variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

How to create a variable as a function of 2 parameters and three other variables

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


Accepted Solutions
Solution
‎12-13-2017 11:26 AM
Super User
Posts: 13,354

Re: How to create a variable as a function of 2 parameters and three other variables

Posted in reply to srinirangan123

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;

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 497

Re: How to create a variable as a function of 2 parameters and three other variables

Posted in reply to srinirangan123

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.

Occasional Contributor
Posts: 11

Re: How to create a variable as a function of 2 parameters and three other variables

Posted in reply to WarrenKuhfeld

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!

Solution
‎12-13-2017 11:26 AM
Super User
Posts: 13,354

Re: How to create a variable as a function of 2 parameters and three other variables

Posted in reply to srinirangan123

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;

 

Occasional Contributor
Posts: 11

Re: How to create a variable as a function of 2 parameters and three other variables

Thanks a lot Ballardw.

 

That worked really well.

 

I appreciate it.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 148 views
  • 0 likes
  • 3 in conversation