BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
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

 

1 REPLY 1
andreas_lds
Jade | Level 19

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;

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
  • 774 views
  • 0 likes
  • 2 in conversation