Here is a method to solve without having sas generate the prime numbers but rather to download them from the internet... * The following was only tested under linux, it would require adjustment for other OS; x cd /home/friedegg; x 'for i in {1..50}; do wget "http://primes.utm.edu/lists/small/millions/primes$i.zip" && unzip "primes$i.zip" && rm -f "primes$i.zip"; done'; data primes; infile '/home/friedegg/primes*.txt' firstobs=3 termstr=crlf end=eof; input prime :??best. @@; if prime=. then delete; if eof then do; call symput('nobs',put(_n_,best.)); call symput('max',put(prime,best.)); end; run; %macro sumprimes(seq1,seq2,seq3,seq4,max,nobs); sasfile work.primes load; %do i=1 %to 4; data _s&&seq&i(sortedby=ptot); obsnum=1; cnt=1; iter=1; ptot=0; do until(obsnum+&&seq&i>&nobs or ptot>&max); set primes point=obsnum; ptot+prime; if cnt=&&seq&i then do; output; iter+1; cnt=1; obsnum=iter; ptot=0; end; else do; obsnum+1; cnt+1; end; end; stop; keep ptot; run; %end; data _null_; length ptots $32000; retain ptots ' '; merge %do i=1 %to 4; _s&&seq&i(in=in&i) %end;; by ptot; if in1 and in2 and in3 and in4 then do; ptots=catx(',', of ptots ptot); call symput('ptots',ptots); end; run; proc sql; select 'SOLUTION FOUND: ' || put(prime,best.) from primes where prime in (&ptots); quit; sasfile work.primes close; %mend; %sumprimes(19,21,405,781,&max,&nobs) SOLUTION FOUND: 9387361
... View more