data have;
input ID $ V1 V2 V3;
cards;
A 12 13 14
A 15 14 14
A 12 15 14
;
data _have;
set have;
array t v:;
grp=_n_;
do i=1 to dim(t);
_v=t(i);
__v=vname(t(i));
output;
end;
keep id _: grp;
run;
proc sort data=_have out=w;
by id __v _v;
run;
data _w;
set w;
by id __v _v;
if not(first._v and last._v) then call missing(_v);
run;
proc sort data=_w out=_w1;
by id grp;
run;
proc transpose data=_w1 out=want(drop=grp _:);
by id grp;
var _v;
id __v;
run;
Here is a Hash Table solution.
data have;
input id $ v1 v2 v3;
n+1;
datalines;
A 12 13 14
A 15 14 14
A 12 15 14
;
run;
proc transpose data=have out=temp;
by id n;
var v:;
run;
proc sort data=temp nouniquekey;
by id _name_ col1;
run;
data want;
if _n_=1 then do;
if 0 then set temp;
declare hash h(dataset:'temp');
h.definekey('id','_name_','col1');
h.definedone();
end;
set have;
array x{*} v:;
do i=1 to dim(x);
_name_=vname(x{i});col1=x{i};
if h.check()=0 then call missing(x{i});
end;
drop i n _name_ col1;
run;
proc print;run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.