Date: Fri, 26 Sep 2008 10:05:55 -0400
Reply-To: Samuel Croker <samuel.croker@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Samuel Croker <samuel.croker@GMAIL.COM>
Subject: Re: hi all,
I to find prime number using Macro program and using base SAS.
In-Reply-To: <200809261337.m8QAlHBt031755@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
This is interesting and as you try to get large you will hit the limit of
precision in data step sas. For example:
SAS integer limit:
9,007,199,254,740,992
C++ unsigned long long:
18,446,744,073,709,551,615
This first came up when I tried to replicate , as an academic exercise,
RANNOR using the datastep and a PIT. I couldn't match the results and
realized that RANNOR is using a precision in the routine that is
unattainable in the data step. You could probably program it using LCGs or
some other technique like that designed to get around numeric precision
limits.
here is an interesting prime site http://primes.utm.edu/curios/
there are lots of optimized routines for prime identification out there.
Cheers,
Sam
On Fri, Sep 26, 2008 at 9:37 AM, Anthony Steel <
PACT.Capacity.Management@uk.fujitsu.com> wrote:
> When dealing with larger primes you could improve the efficiency of the do
> loop by setting the range of j to be 2 to the square root of i, as this
> will still encompass all possible factors of i.
>
> On Fri, 26 Sep 2008 06:15:01 -0700, Dirk Nachbar <dirknbr@GOOGLEMAIL.COM>
> wrote:
>
> >On Sep 26, 4:55 am, Satya <kondal4u...@gmail.com> wrote:
> >> hi all
> >> I to find prime number from 1 to 20 using Macro program and using
> >> base SAS.
> >> I tried but that code is some how big .
> >> Bye.
> >
> >hi
> >
> >here is ths solution
> >
> >option mprint;
> >%macro prime(n);
> >data prime;
> >do i=1 to &n;
> > prime=1;
> > do j=2 to ceil(i/2);
> > if mod(i,j)=0 then prime=0;
> > end;
> > if prime=1 then output;
> >end;
> >run;
> >%mend;
> >%prime(20);
>
--
Samuel T. Croker
Lexington, SC
Charlotte, NC
|