BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SPR
Quartz | Level 8 SPR
Quartz | Level 8

SAS course on proc OPTMODEL suggests that object function can be defined by simple formula: e.g. MAX Y=X**2. Is possible to use more complicated SAS code (execute macros, SQL queries, data steps etc.) in this case?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@SPR wrote:
Thanks ballardw for your reply. However I need more clarification. Assume we have a code:
Proc OPTMODEL;
...
max y= data a; set b; y+c**2; run;
...
quit;
My question is: will this procedure stop hitting data step "run;" or will continue up to "quit;"?
Thanks

My general answer is to try it and see. (Save data an code before hand just in case you manage to create a truly pathological error that renders the SAS session unstable.)

 

I don't use OPTMODEL but I am fairly sure that when you write a constraint, such as in your example, that "data" is going to be interpreted as a variable and would expect an operator between the variable "data" and the variable "a". The first ; would end the constraint and what follows would start a new statement.

 

View solution in original post

4 REPLIES 4
ballardw
Super User

If the macro generates function code without other procedures it could. Remember all that SAS macro code does is generate code. So what it is acceptable depends on where it starts.

 

As soon as SAS encounters a procedure other than the one currently being used or the start of a data step that current procedure will consider that a "run;" has been implied and attempt to execute with the code.

Consider:

Proc print data=sashelp.class;

Proc print data=sashelp.cars;

The first Proc Print executes because when the second Proc Print is called SAS implies a Run; before the second. So you get output for printing Sashelp.class. The second Proc print does not have a run statement or a procedure boundary so will sit there waiting for either more proc print options, a run or another Proc/data step.

 

 

SPR
Quartz | Level 8 SPR
Quartz | Level 8
Thanks ballardw for your reply. However I need more clarification. Assume we have a code:
Proc OPTMODEL;
...
max y= data a; set b; y+c**2; run;
...
quit;
My question is: will this procedure stop hitting data step "run;" or will continue up to "quit;"?
Thanks
ballardw
Super User

@SPR wrote:
Thanks ballardw for your reply. However I need more clarification. Assume we have a code:
Proc OPTMODEL;
...
max y= data a; set b; y+c**2; run;
...
quit;
My question is: will this procedure stop hitting data step "run;" or will continue up to "quit;"?
Thanks

My general answer is to try it and see. (Save data an code before hand just in case you manage to create a truly pathological error that renders the SAS session unstable.)

 

I don't use OPTMODEL but I am fairly sure that when you write a constraint, such as in your example, that "data" is going to be interpreted as a variable and would expect an operator between the variable "data" and the variable "a". The first ; would end the constraint and what follows would start a new statement.

 

SPR
Quartz | Level 8 SPR
Quartz | Level 8
Thanks for clarification. It seems to to I found possible solution to use SAS code inside proc OPTMODEL: it is CALL FCMP. I can do a lot of programming inside the function to calculate complicated object function.