I am looking for a solution to the problem.
I have a number, let's say it 234534, and I would like to have this set of numbers in between 123423 and 345645.
234534 - 111111 = 123423
234534 + 111111 = 345645
but not in such a simple way:
data test;
%do i = 1 %to 3;
%do j = 2 %to 4;
%do k = 3 %to 5;
%do l = 4 %to 6;
%do m = 2 %to 4;
%do n = 3 %to 5;
i = &i;
j = &j;
k = &k;
l = &l;
m = &m;
n = &n;
output;
%end;
%end;
%end;
%end;
%end;
%end;
run;
because for me, numbers closer to the original are better or sorted like this:
| 234534 | or | 234534 |
| 334534 | 134534 | |
| 244534 | 224534 | |
| 235534 | 233534 | |
| and so far | and so far | |
| 134534 | 334534 | |
| 224534 | 244534 | |
| 233534 | 235534 | |
| and so far | and so far | |
| 344534 | 124534 | |
| and so far | and so far | |
| 144534 | 324534 | |
| and so far | and so far | |
| 345534 | 123534 | |
| and so far | and so far |
Thank you for your help
Assuming I understand what you are aiming for, here's an approach:
data want;
original_i = 2;
original_j = 3;
original_k = 4;
original_l = 5;
original_m = 3;
original_n = 4;
do i = original_i - 1 to original_i + 1;
do j = original_j - 1 to original_j + 1;
do k = original_k - 1 to original_k + 1;
do l = original_l - 1 to original_l + 1;
do m = original_m - 1 to original_m + 1;
do n = original_n - 1 to original_n + 1;
distance = abs(i - original_i) + abs(j - original_j) + abs(k - original_k) +
abs(l - original_l) + abs(m - original_m) + abs(n - original_n);
output;
end; end; end; end; end; end;
run;
Then you can sort the data set by DISTANCE.
Even if I didn't get the problem exactly right, this ought to be close enough that you can adjust it as needed.
I don't understand what you are trying to achieve. Why are you using macro-loops? I don't think they are necessary. In general: start with working, macro-free code and use macro-statements only to make the code dynamic.
Assuming I understand what you are aiming for, here's an approach:
data want;
original_i = 2;
original_j = 3;
original_k = 4;
original_l = 5;
original_m = 3;
original_n = 4;
do i = original_i - 1 to original_i + 1;
do j = original_j - 1 to original_j + 1;
do k = original_k - 1 to original_k + 1;
do l = original_l - 1 to original_l + 1;
do m = original_m - 1 to original_m + 1;
do n = original_n - 1 to original_n + 1;
distance = abs(i - original_i) + abs(j - original_j) + abs(k - original_k) +
abs(l - original_l) + abs(m - original_m) + abs(n - original_n);
output;
end; end; end; end; end; end;
run;
Then you can sort the data set by DISTANCE.
Even if I didn't get the problem exactly right, this ought to be close enough that you can adjust it as needed.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.