BookmarkSubscribeRSS Feed
makset7
Obsidian | Level 7

Hello
I have a small optimization problem.
I have two series of data and I would like to optimize the differences between them.

I could use a loop but I know that sas has optimizing functions but I do not know it.

Maybe someone will help me.

The problem looks as follows.

 

data test;
input n $ x $ y;
datalines;
1	1	1
2	0.534825871	0.390243902
3	0.667910448	0.609756098
4	0.140547264	0.048780488
5	0.237562189	0.195121951
6	0	0
7	0.630597015	0.048780488

;
run;

data test;
set test;
z = abs(x - y);
sum_z = ( z + lag1(z) + lag2(z) + lag3(z) + lag4(z) + lag5(z) + lag6(z) );
run;

data test;
set test;
z1 = abs(x - (y + 0.01));
sum_z1 = ( z1 + lag1(z1) + lag2(z1) + lag3(z1) + lag4(z1) + lag5(z1) + lag6(z1) );
run;

data test;
set test;
z2 = abs(x - (y + 0.02));
sum_z2 = ( z2 + lag1(z2) + lag2(z2) + lag3(z2) + lag4(z2) + lag5(z2) + lag6(z2) );
run;
/******* ******** *******/
data test; set test; z6 = abs(x - (y + 0.06)); sum_z6 = ( z6 + lag1(z6) + lag2(z6) + lag3(z6) + lag4(z6) + lag5(z6) + lag6(z6) ); run;

Thank you for your help

 

 

optimize the differences between x and y -> the differences are presented (example) in the variable sum_z to sum_z6

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

What exactly are you trying to optimize?

 

Can you be a bit more specific in your explanation?

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
  • 1 reply
  • 648 views
  • 0 likes
  • 2 in conversation