BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

I have a table like this:

Parent  Child

A            B

B            C

C            D

I             J

J           K

K          L

i want to write a query which which output values which are parent only having no child.

Output  A and I 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

I think this is what you want:

data have;
 input Parent $ Child $;
 cards;
A            B
B            C
C            D
I            J
J            K
K            L
;
run;

PROC SQL noprint;
 create table want as
 select Parent
 from have
 where Parent NOT IN (select Child from have)
;
QUIT;

dm 'FSV';
/* end of program */

Koen

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

I think this is what you want:

data have;
 input Parent $ Child $;
 cards;
A            B
B            C
C            D
I            J
J            K
K            L
;
run;

PROC SQL noprint;
 create table want as
 select Parent
 from have
 where Parent NOT IN (select Child from have)
;
QUIT;

dm 'FSV';
/* end of program */

Koen

singhsahab
Lapis Lazuli | Level 10

@Aexor can be solve by using Hash Object 

 


data want;
if _n_ eq 1 then do;
declare hash h(dataset:'have');
h.defineKEY('Child');
h.definedata('parent');
h.definedone();
end;
do until ( eof2 ) ;
 set have end = eof2 ;
 if h.find(key:parent) ne 0 then 
 OUTPUT;
 end ;
 stop ; 
run;

 Regards,

 SS

PeterClemmensen
Tourmaline | Level 20

I suspect you want to know more than just A and I here?

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
  • 3 replies
  • 1237 views
  • 2 likes
  • 4 in conversation