@valarievil
You have received the solution already.
Without explicit sorting of data sets, we can use hash objects to get your solution with the aggregated sum within Gender. Here is one way of using hash objects. Assuming SALES data set will be huge, place other two data sets into hash tables. As each record from Sales are processed, the (Price * Quantity) can be accumulated by replacing SUM in the hash table (E). Finally, we can write out the contents of E into a WANT data set.
Edited: data _null_;
if _n_ = 1 then do;
if 0 then set parts;
Sum = 0;
declare hash p(dataset:'Parts');
p.definekey('partno');
p.definedata('price');
p.definedone();
declare hash e ();
e.definekey('ID');
e.definedata('ID','gender','DOB','Sum');
e.definedone();
do until(eof);
set employ end = eof;
e.add();
end;
end;
set sales end = last;
rp = p.find();
re = e.find(); if rp = 0 and re = 0 then do;
Sum + price * quantity;
e.replace(); end;
if last;
e.output(dataset:'want');
run;
The output of WANT is:
... View more