Another way of achieving the goal in a single step is using CALL VNEXT instead of the dual arrays (as suggested by @mkeintz on SAS-L) coupled with CALL EXECUTE:
data have ;                                     
  input ID :$3. X_1 X_2 X_3 Y_1 Y_2 W_3  :$1. ; 
  cards ;                                       
ID1 1 2 3 4 5 6 C                               
ID2 2 3 4 5 6 7 D                               
run ;                                           
                                                
data _null_ ;                                   
  set have (obs = 1) ;                          
  length _vn $ 32 ;                              
  call execute ("data want; set have(keep=") ;  
  do until (cmiss (_vn)) ;                      
    call vnext (_vn) ;                          
    if find (_vn, "3") then call execute (_vn) ;
  end ;                                         
  call execute ("); run;") ;                    
run ;                                           
Kind regards
Paul D.