If I understood your program correctly, it is not what I was up to. In fact, my final code was very similar to Xia Keshan's (will set his answer to correct shortly). I hope the following code demonstrates, why I did not choose proc sql but a hash table: Data A; Input Prod Comp; Datalines; 1 33 1 44 2 11 2 55 2 66 ; Data B; Input Comp Subcomp; Datalines; 33 111 33 222 55 666 55 777 55 888 ; Proc SQL; Select A.Prod, A.Comp, B.Subcomp From A, B Where A.Comp eq B.Comp; Quit; Data Want (Drop=rc); Length Comp 8. Subcomp 8.; If _N_ eq 1 Then Do; Declare Hash H (Dataset:'B',Multidata:'y'); H.Definekey('Comp'); H.Definedata('Subcomp'); H.Definedone(); Call Missing (Comp, Subcomp); End; Do While (not Eof); Set A End=Eof; rc=H.Find(); If (rc) Then Do; Call Missing (Subcomp); Output; End; Do While (not rc); Output; rc=H.Find_next(); End; End; Run; Proc Print Data=Want; Run;
... View more