BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rj438
Calcite | Level 5
Many, unfortunately. Someone put the average of a state data for many variables to fill missing for each county/city. I don't want to use the average, so need to get rid of them!


novinosrin
Tourmaline | Level 20
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;
Ksharp
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 17 replies
  • 2864 views
  • 0 likes
  • 7 in conversation