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.
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;
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.
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.