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

Dear all,

 

how can exclude a group of observations in terms of one observation?

 

for example, in following observations,

 

 

psn_name_cited, docdb_family_id, psn_name_citing 

apple,1,pear

apple,1,apple

apple,2,orange 

apple,2,banana

apple,2, pear

juice,3, bottle

orange,3,water

I would like to exclude the following observations

 

apple,1,pear

apple,1,apple

by using the following codes,

 

PROC SQL;
   CREATE TABLE want  AS
      SELECT
       *
      FROM
        tryy
      GROUP BY psn_name_cited,docdb_family_id
      Having psn_name_cited ne psn_name_citing /* exclude self_citation */
;
QUIT;

 

 

However, only

apple,1,apple

 

been excluded from the sample.

 

Could you please give me some suggestions about this?

 

Thanks in advance.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
PROC SQL;
   CREATE TABLE want  AS
      SELECT
       *
      FROM
        tryy
      GROUP BY psn_name_cited,docdb_family_id
      Having sum(psn_name_cited = psn_name_citing)=0 /* exclude self_citation */
;
QUIT;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Maybe joining psn_name_citing back on by psn_name_citing=psn_name, something like:

proc sql;
  create table want as
  select a.*
  from   have a
  left join have b
  on      a.psn_name=b.psn_name_citating
  where b.psn_name_citing="";
quit;

Not tested, post test data in the form of a datastep in future.

Ksharp
Super User
PROC SQL;
   CREATE TABLE want  AS
      SELECT
       *
      FROM
        tryy
      GROUP BY psn_name_cited,docdb_family_id
      Having sum(psn_name_cited = psn_name_citing)=0 /* exclude self_citation */
;
QUIT;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1185 views
  • 1 like
  • 3 in conversation