I'm trying to write a following function that I would like to minimize using a sas optlso. But I'm having difficulty in figuring out the logic. Any help in creating the logic would be very helpful.
here is the function:
The part that I cannot figure out is i ne j ne k ne i. If you can modify the below code to reflecy te a
Below is a reproducible example. Any help would be greating appreciated.
proc fcmp outlib=sasuser.myfuncs.mypkg; function fdef1(x1, x2,x3,x4,x5,x6,x7); array x[7]; array y[7,7] /nosym ( 1.0000 4.0000 9.0000 6.0000 6.0000 5.0000 5.0000 0.2500 1.0000 7.0000 5.0000 5.0000 3.0000 4.0000 0.1111 0.1429 1.0000 0.2000 0.2000 0.1429 0.2000 0.1667 0.2000 5.0000 1.0000 1.0000 0.3333 0.3333 0.1667 0.2000 5.0000 1.0000 1.0000 0.3333 0.3333 0.2000 0.3333 7.0000 3.0000 3.0000 1.0000 2.0000 0.2000 0.2500 5.0000 3.0000 3.0000 0.5000 1.0000); fx = 0; do i= 1 to dim(y); do j = i+1 to dim(y); do k = 1 to dim(y); fx = fx + ((y[i,k]*y[k,j])-(x[i]/x[j]))**2; end; end; end; return(fx); endsub; run;
One additional question: Is there a way to print out the indices i j and k in the loop to a SAS log/dataset to QC ?
Is this what you need:
if i ne j and j ne k and k ne i then fx = fx + ((y[i,k]*y[k,j])-(x[i]/x[j]))**2;
Is this what you need:
if i ne j and j ne k and k ne i then fx = fx + ((y[i,k]*y[k,j])-(x[i]/x[j]))**2;
Thank you very much. Can you please also let me know if I can print i,j,k to the log or lst ?
Likely not to LST, but did you try something like:
Put "In function FDEF1 " i=;
Completely untested though.
I can see a use for debugging with this but since functions can get many times in a procedure or datastep I would recommend not leaving them in the final version.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.