data ds;
array x[10] ( 1, 2, 3, 4, 5, 6, 7, 8, 9,10);
do i = 1 to dim(x);
if mod(x[i], 2) = 0 then do;
even_number = x[i];
output;
end;
end;
drop i;
proc print noobs;
run;
i want output like below
| x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 | even_numbers |
| 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
| 0 | 0 | 0 | 4 | 0 | 0 | 0 | 0 | 0 | 0 | 4 |
| 0 | 0 | 0 | 0 | 0 | 6 | 0 | 0 | 0 | 0 | 6 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 0 | 0 | 8 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 10 |
A different approach:
data want;
array x[10] x1 - x10 (10*0);
do even_numbers = 2 to 10 by 2;
x[even_numbers] = even_numbers;
output;
x[even_numbers] = 0;
end;
run;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.