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?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1016 views
  • 0 likes
  • 2 in conversation