PC SAS 9.1.3, no SAS/OR (otherwise PROC CLP constraint programming would be fun to play with in addition to PROC OPTMODEL). Can't vouch for efficiency, but it works. %let r1= 100; %let r2= 316; data soln(keep=c1-c3 dUsedOnce); do i = &r1 to &r2; *--- generate combinations; c1 = put( i*i, z5. ); do j = i+1 to &r2; c2 = put( j*j, z5. ); do k = j+1 to &r2; *--- using i+1 and j+1 generates lower triangular only; c3 = put( k*k, z5. ); link Chkit; *--- check this combination; end; end; end; return; Chkit: length c1-c3 $ 5 str15 $ 15; array digit[10] $ d1-d10 ('1','2','3','4','5','6','7','8','9','0'); array used[10] u1-u10; array freq[10] f1-f10; str15 = cat( c1, c2, c3 ); do d = 1 to 10; *--- calc freq and used indicator; freq = countc( str15, digit ); used = ( freq > 0 ); if freq = 1 then dUsedOnce = digit ; end; if sum(of used ) ~= 5 then return; *--- use 5 different digits; do d = 1 to 10; if used then do; *--- if d is used; if freq = d then return; *--- not used its own # of times; if used[freq ] = 0 then return; *--- freq is used; do p = 1 to d-1; *--- if p is used, must be different # of times; if used > 0 then if freq = freq then return; end; end; end; output; return; run; proc sql; select * from soln group by dUsedOnce having count(*)=1; quit; Hats off to PROC FCMP, very nice approach. Never used it, so I learned something valuable out of this.:smileygrin: Message was edited by: DLing (minor cleanup)
... View more