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

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:

 

equation.JPG

 

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

3 REPLIES 3
ballardw
Super User

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;

Forecaster
Obsidian | Level 7

Thank you very much. Can you please also let me know if I can print i,j,k to the log or lst ?

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1318 views
  • 1 like
  • 2 in conversation