call java class from SAS. ERROR: Can not find class

    data Numbers;
        do i=1 to 10;

    data PrimeNumbers;
        set Numbers;
        if _N_=1 then declare javaobj j("C:\Program Files\Java\jdk1.7.0_10\bin\checkPrimeNumber");
        if isPrimeNumber=1 then output;

    /*-SET CLASSPATH "C:\Program Files (x86)\Java\jre7\bin"*/

    /*--------------------------Sample java code----------------------------
    public class checkPrimeNumber
        public checkPrimeNumber()
        public static void main(String args[])
            checkPrimeNumber CPN=new checkPrimeNumber();
            System.out.println ("Result:"+CPN.checkPrimeNumber(23));
        public int checkPrimeNumber(int num)
            for (int i=2; i<=(num/2); i++)
                if ((num%i) == 0)
                 return 0;
            return 1;


        ERROR: Could not find class C:\checkPrimeNumber at line 45 column 44.  Please ensure that the
               CLASSPATH is correct.
        ERROR: DATA STEP Component Object failure.  Aborted during the EXECUTION phase.
        java.lang.ClassNotFoundException: C:\checkPrimeNumber
             at$ Source)
             at Method)
             at Source)
             at java.lang.ClassLoader.loadClass(Unknown Source)
             at java.lang.ClassLoader.loadClass(Unknown Source)

I have set the CLASSPATH environment variable to C:\Program Files\Java\jdk1.7.0_10\bin and compiled & executed the program from command prompt. Code works fine from command prompt. But SAS code throws an Error, so I added -set CLASSPATHC:\Program Files\Java\jdk1.7.0_10\binstatement insasv9.cfglocated atSASFoundation\9.3\nls\en`. I still get the same error( same as mentioned above). What could be wrong? Where should I add classpath variable in SAS files/folders so that SAS identify java classpath?

In your sasv9.cfg file you should look for -JREOPTIONS option. Inside this option add you path to the parameter

When declaring java object in data step you can pass only the class name - not the all path. So the declaration should looks like:

declare javaobj j("checkPrimeNumber")

And the last one. The return value from java method is passed to the last argument in data step function. Calling java method should go like this:


Cheers, Chris