turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- How to create a variable as a function of 2 parame...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-10-2017 11:36 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to srinirangan123

12-11-2017 11:33 AM

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;

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to srinirangan123

12-10-2017 12:21 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to WarrenKuhfeld

12-10-2017 10:15 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to srinirangan123

12-11-2017 11:33 AM

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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

12-13-2017 11:27 AM

Thanks a lot Ballardw.

That worked really well.

I appreciate it.