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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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