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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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