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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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