/* test data */
data one;
input score1 - score3;
cards;
11 12 13
21 . 23
. 32 33
. . 43
51 . .
. . 63
. . .
;
run;
/* "compact" the scores by bubbling non-missings to the left */
data two;
set one;
array scores score1-score3;
drop i j temp;
do i = 1 to 3-1;
do j = 3 to i+1 by -1;
if missing(scores(j-1)) and not missing(scores(j)) then do;
temp = scores(j-1);
scores(j-1) = scores(j);
scores(j) = temp;
end;
end;
end;
run;
/* check */
proc print data=two;
run;
/* on lst
Obs score1 score2 score3
1 11 12 13
2 21 23 .
3 32 33 .
4 43 . .
5 51 . .
6 63 . .
7 . . .
*/
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.