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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 415 views
  • 0 likes
  • 2 in conversation