BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ilikesas
Barite | Level 11

Hi,

suppose that I have the following table:

CompanydatenameValue
A20/10/2010A112e
A20/10/2010A2
A25/02/2012A1e4
A25/02/2012A2h5
B20/10/2010B1w3
B20/10/2010B2wr

There is a missing value in the table, so I want to delete its row, as well as all the rows of the same Company-date combination, so the new table should be like this:


Companydatenamevalue
A25/02/2012A1e4
A25/02/2012A2h5
B20/10/2010B1w3
B20/10/2012B2wr



Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select * from have

group by company, date

having sum(value='')=0;

quit;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

* DOW loops ;

data want ;

  do until (last.date);

    set have ;

    by company date ;

    any = any or missing(value);

  end;

do until (last.date);

   set have ;

   by company date ;

  if not any then output;

end;

drop any ;

run;

* or Self merge ;

data want ;

  merge have have (in=in2 keep=company date value rename=(value=_value) where=(missing(_value))) ;

  by company date ;

  if in2 then delete ;

  drop _value;

run;

Haikuo
Onyx | Level 15

2XDOW/PROC SQL plus CMISS() should do.

data want;

do until (last.date);

set have;

by company date;

if cmiss(of _all_) >0 then flag=1;

end;

do until (last.date);

set have;

by company date;

if flag ne 1 then output;

end;

run;

If using Proc SQL, then you can't use _all_. You can either spell all of your variable explicitly or pull them out using dictionary.columns if you have a lot variables to save some typing.

Haikuo

stat_sas
Ammonite | Level 13

proc sql;

create table want as

select * from have

group by company, date

having sum(value='')=0;

quit;

Patrick
Opal | Level 21

Or hash:

data want;

  set have;

  if _n_=1 then

    do;

      dcl hash h(dataset:'have(where=(missing(value)))');

      _rc=h.defineKey('company','date');

      _rc=h.defineDone();

      drop _rc;

    end;

  if h.check()=0 then delete;

run;

ilikesas
Barite | Level 11

Please note that all the codes here give the desired result (I wish that I could mark them all as Correct or Helpful).

For a beginner like me the simplest and most intuitive code is the one by stat@sas, but I learned much from the other codes and therefore I thank all of you for helping!!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 1307 views
  • 6 likes
  • 5 in conversation