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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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