Try the following program. If you don't need the column names to be maintained, you can drop
the last data step.
data have;
input level cniv1-cniv8;
cards;
5 1 3 0 2 4 . . .
;
run;
data want;
set have;
array revcniv(*) revcniv8-revcniv1;
array cniv(*) cniv1-cniv8;
j=1;
do i=dim(cniv) to 1 by -1;
if cniv(i) ne . then do;
revcniv(j)=cniv(i);
j+1;
end;
end;
drop cniv: i j;
run;
/* Renale columns back to cniv* */
data _NULL_;
set want;
length NAME $32.;
call execute('data want; set want;');
do while (NAME ne "NAME");
call vnext(NAME);
if upcase(NAME)=:"REV" then do;
call execute(cat('rename ',NAME,"=",substr(NAME,4),";"));
end;
end;
call execute('run;');
stop;
run;
... View more