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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.