It is numeric or character type variable ?
data have;
infile cards truncover;
input Name $ Col1 Col2 Col3 Col4;
cards;
ABC 1245 7890 . 1290
XRT 5634 2384 1276
UTR 6734 5689 6365 1251
;
run;
data want;
set have;
array x{*} col1-col4;
array y{*} new1-new4;
call sortn(of x{*});
n=0;
do i=1 to dim(x);
if not missing(x{i}) then do;n+1;y{n}=x{i};end;
end;
drop n i col:;
run;
data want;
set have;
array cols {*} col1-col4;
do i = dim(cols) - 1 to 1 by -1;
if cols{i} = . and cols{i+1} ne . then cols{i} = cols{i+1};
end;
drop i;
run;
PS if col1 to colX are of type character, use ' ' instead of the dot for a missing value.
Edit: added "by -1" in the do statement.
It is numeric or character type variable ?
data have;
infile cards truncover;
input Name $ Col1 Col2 Col3 Col4;
cards;
ABC 1245 7890 . 1290
XRT 5634 2384 1276
UTR 6734 5689 6365 1251
;
run;
data want;
set have;
array x{*} col1-col4;
array y{*} new1-new4;
call sortn(of x{*});
n=0;
do i=1 to dim(x);
if not missing(x{i}) then do;n+1;y{n}=x{i};end;
end;
drop n i col:;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.