BookmarkSubscribeRSS Feed
FrankB
Fluorite | Level 6

I get the error message when I try to run the following sas code on SAS UNIX server but the code runs without any error on local windows computer. I was wondering if someone know the possible cause for this error.

 

rsubmit;
proc fcmp outlib=work.ds.functions; function Tot_profit(V5YC, ...); rc = run_macro('Profit',...); if rc eq 0 then return(Sum_profit2); else return(.); endsub; run;


options cmplib=work.ds;
proc optmodel;

VAR V5YC init 1, F1YC init 1,F2YC init 0,F3YC init 3.20111035,F4YC init 3.20111035,F5YC init 3.20111035;
MAX Total_profit = Tot_profit( V5YC, ... );

CON A: 3.29>= F3YC >= 2.89;
CON B: 3.89>= F4YC >= 2.39;
CON C: 4.49>= F5YC >= 2.44;

solve with nlp /tech=ip ms msnumstarts=50 msprintlevel=5 printfreq=50 MSDISTTOL=10000;

quit; run;

endrsubmit;

 

5 REPLIES 5
ChrisHemedinger
Community Manager

From the PROC OPTMODEL doc:

 

Not all PROC FCMP functionality is compatible with PROC OPTMODEL; in particular, the following FCMP functions are not supported and should not be called within your FCMP function definitions: READ_ARRAY, WRITE_ARRAY, RUN_MACRO, and RUN_SASFILE. In many cases, OPTMODEL capabilities can replace these functions. Matrix arguments can be used in place of the READ_ARRAY function by using the READ DATA statement to load the matrix in PROC OPTMODEL. Similarly, you can replace the WRITE_ARRAY function in an FCMP subroutine by copying the matrix to an output argument and using the OPTMODEL procedure to write the matrix. You can use the SUBMIT statement in place of the RUN_MACRO and RUN_SASFILE functions.

 

That doesn't explain why you find that it works on your local SAS, unless perhaps more support was added in a later version of SAS and that's what you're running locally.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
FrankB
Fluorite | Level 6
Hi,

Thanks for the response.

As I explained the proc fcmp is working well with proc optmodel on my
Windows PC but the error appears when I run it on UNIX server using
rsubmit. I believe the problem is not generated from proc optmodel but it's
only from the remote submit of proc fcmp since when I run the following
code I get the same error (ERROR: Cannot find a library containing
subroutine RUN_MACRO.).

rsubmit ;
proc fcmp outlib=xwork.ds.functions;

function Tot_profit(V5YC, F1YC, F2YC, F3YC, F4YC, F5YC,seg
$,peak,Num_comp_periods,Num_pay_period_year,Discount_rate,Free_Appr_cost,Amex_Point_Cost,cash_back_cost);
rc = run_macro('Profit',V5YC, F1YC, F2YC, F3YC, F4YC,
F5YC,seg,peak,Num_comp_periods,Num_pay_period_year,Discount_rate,Free_Appr_cost,Amex_Point_Cost,cash_back_cost,Sum_profit2,NII2,Vol2);
if rc eq 0 then return(Sum_profit2);
else return(.);
endsub;

endrsubmit;



The reason that I'm using proc fcmp (called "Tot_profit") to create a
function which calls a macro function (called "Proft"). The Tot_profit
function is later called from proc optmodel to calculate the objective
function and the input arguments to that function is the optimization
variables and the outcome is the objective value which is supposed to be
maximized. If I just call the macro function directly from the proc
optmodel without utilizing the function created by proc fcmp then I get the
following error message for any line of code I add after calling the macro
function.

ERROR 180-322: Statement is not valid or it is used out of proper order.

So please let me know your thoughts about the first error message from
remote submit of proc fcmp and also if you have any suggestion for calling
a macro function during optimization directly from proc optmodel without
utilizing proc fcmp.

Thanks,
Farshid


##- Please type your reply above this line. Simple formatting, no
attachments. -##
RobPratt
SAS Super FREQ

Can you please show your Profit macro?

FrankB
Fluorite | Level 6

Unfortunately I can't share the details but it involved several proc sqls and data steps to generate the output profit (SUM_PROFIT2) using the given inputs:

 

 

%MACRO Profit(seg=,....);


proc sql;
....
quit;



proc sql;
....
quit;



proc sql;
....
quit;


proc sql;
....
quit;


proc sql;
....
quit;

/*Summarize the costs*/
proc sql;
....
quit;

/*application costs*/
proc sql;
....
quit;


data APP_COST;
...
run;

/*Out_Profit*/
	
/*%let mydataid=%sysfunc(open(Out_Profit, i));*/
data _NULL_;
%GLOBAL SUM_PROFIT2;
	set OUT_PROFIT;
	call SYMPUT('SUM_PROFIT2',sum_profit);
run;
%let result = &SUM_PROFIT2;
%MEND Profit;

 

FrankB
Fluorite | Level 6

I checked the version that I have on my local computer which was 9.03.01M1P110211 for Base SAS and the one that is running on UNIX server: 9.03.01M2P080112 . Although the one that runs on the server is more recent but the library error appears on this version but not the old version on my local.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1420 views
  • 0 likes
  • 3 in conversation