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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 561 views
  • 2 likes
  • 4 in conversation