SAS Optimization, and SAS Simulation Studio

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

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

04-18-2017 09:26 AM

Hello,

Stack overflow could not help me so and referred me here.

ref: http://stackoverflow.com/questions/42804051/obtaining-minimum-maximum-output-of-a-macro-function

I want to find to find extreme values produced by a macro as a function of input parameters:

For example purposes here is some data:

```
data Input_data;
input X Y;
cards;
10 15
20 18
30 27
33 41
;
run;
```

The following is not the actual formula (as the minimum for this is easily found analytically.) and I want computational method. For examples sake I have semi-empirical rule, which takes three parameters in:

```
%macro Function(const1, const2 const3);
data output;
set input;
X_eff1=((X > &const1.)*(X - &const1.)**2);
X_eff2=((X > &const2.)*(X - &const2.)**2);
X_eff3=((X > &const3.)*(X - &const3.)**2);
Residual= Y - (1.3*X_eff1 - 2.7*X_eff2+ 3.1*X_eff3);
run;
%mend;
```

**I want the find const1, const2 const3 which produce the minimum value for variable 'Residual'. **For sake of argument, lets say minimum of sum(abs(residual)).

Can SAS do this? Few options that are to be considered:

a) Find global minimum

b) Find local minimum within boundary conditions, for example: `const1[0,1]`

`const2[10,17]`

, `const3[20, 22]`

I could generate huge table and brute force feed it to the function. However, this is not feasible if the number of input parameter rise.

I could scratch program something?

I could do this in numpy (fmin from cipy.optimize comes to mind)or R if it proves hard for SAS.

Any thoughts on how to solve it?

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

Posted in reply to Pinegulf

04-18-2017 09:40 AM

Sounds like a proc iml problem to me all those matrices. I will however move this over to the stats section.

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

Posted in reply to Pinegulf

04-18-2017 09:49 AM

You could program it yourself in this fashion:

data want;

set have;

min_residual = 999;

do const1 = 0 to 1 by 0.01;

do const2 = 10 to 17 by 0.01;

do const3 = 20 to 22 by 0.01;

* Calculations using no macro variables, only const1 const2 and const3;

if abs(residual) < min_residual then do;

min_residual = abs(residual);

min_const1 = const1;

min_const2 = const2;

min_const3 = const3;

end;

end;

end;

end;

run;

You can adjust the fineness of the grid, depending on how many constants you have, how many observations you have, and how much time you have to wait for the program to complete. Also, you may want to add another variable to track whether the minimum residual is positive or negative.

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

Posted in reply to Astounding

04-19-2017 01:32 AM

The brute force approach works in the case of the example.

However, I'm working with rather large datasets (about 1gb) and the actual number of variables may be larger.

However, I'm working with rather large datasets (about 1gb) and the actual number of variables may be larger.

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

Posted in reply to Pinegulf

04-18-2017 09:56 AM - edited 04-18-2017 09:57 AM

The standard ways to solve an optimization problem (constrained or unconstrained) in SAS are:

1. Use one of the NLP routines in SAS/IML. For an overview and many links, see the article "Ten tips before you run an optimization" or see the SAS/IML documentation for many examples.

2. PROC OPTMODEL in SAS/OR software provides a simpler syntax and a wide variety of solvers.

Do you have a license for either SAS/IML and/or SAS/OR software?

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

Posted in reply to Rick_SAS

04-19-2017 01:10 AM

>Do you have a license for either SAS/IML and/or SAS/OR software?

Sorry, no.

Sorry, no.

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

Posted in reply to Pinegulf

04-18-2017 09:56 AM

Moved this thread to mathematical optimization, which only helps if you have the module though.

Do you know what's included in your SAS license?

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

Posted in reply to Reeza

04-19-2017 01:33 AM

These are the packages I hae access to:

PROC SETINIT; run;

-Base SAS Software

---SAS/STAT

---SAS/GRAPH

---SAS/ETS

---SAS/OR

---SAS/Secure 168-bit

---SAS/Secure Windows

---SAS Enterprise Guide

---OR OPT

---OR PRS

---OR IVS

---OR LSO

---SAS/ACCESS Interface to PC Files

---SAS/ACCESS Interface to OLE DB

---SAS Workspace Server for Local Access

---High Performance Suite

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

Posted in reply to Pinegulf

04-19-2017 01:40 AM

Then look at PROC OPTMODEL as per Ricks suggestion above.

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

Posted in reply to Pinegulf

04-18-2017 10:19 AM

I haven't fully understood what you are up to, but maybe take a look at proc model (http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_model_sect011....) or proc optmodel.

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

Posted in reply to Pinegulf

04-19-2017 03:10 AM

http://blogs.sas.com/content/iml/2017/04/12/quadratic-optimization-sas.html