If you want to limit the number of columns generated to just 3 then perhaps that is an input parameter? How do you know which variables to scan? Perhaps that is another input parameter. * create example data ; data have; input ID $ VAR1-VAR5; cards; 101 1 1 . . 1 102 . . 1 . . 103 1 1 . . . ; run; * set parameters ; %let maxout=3 ; %let varlist = _numeric_ ; * process the file ; data want ; set have ; array num &varlist ; array col (&maxout) $32 ; do _i=1 to dim(num) until (_n=&maxout); if num(_i) then do ; _n=sum(_n,1); col(_n)=vname(num(_i)); end; end; drop _i _n ; run; Obs ID VAR1 VAR2 VAR3 VAR4 VAR5 col1 col2 col3 1 101 1 1 . . 1 VAR1 VAR2 VAR5 2 102 . . 1 . . VAR3 3 103 1 1 . . . VAR1 VAR2
... View more