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

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!

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
  • 1305 views
  • 1 like
  • 2 in conversation