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?

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 1037 views
  • 2 likes
  • 4 in conversation