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
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
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
@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
I suspect you want to know more than just A and I here?
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.
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.