SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Sk4r
Obsidian | Level 7

Hi, I've got some java classes stored on a directory that a SAS program uses, problem is that I dont know how to add the path to that directory to the Classpath, so the program can run correctly. That's the problem that I'd like to solve.

 

I've tried adding a set path statement con the sasconfig file and adding the path to the environment variable (I am working on a Windows 7 OS and SAS 9.4/ EG 7.1).

 

Thank you in advance.

14 REPLIES 14
Sk4r
Obsidian | Level 7

Thank you for your response, I got this warning "WARNING: Could not initialize classpath. Classpath variable is not set."

 

NOTE: Argument not valid for the function SYSGET('CLASSPATH').......

NOTE: Ignore any messages from the next statement(s)

 

I think it wasn't set correctly then

andreas_lds
Jade | Level 19

@Sk4r wrote:

Thank you for your response, I got this warning "WARNING: Could not initialize classpath. Classpath variable is not set."

 

NOTE: Argument not valid for the function SYSGET('CLASSPATH').......

NOTE: Ignore any messages from the next statement(s)

 

I think it wasn't set correctly then


This error occurs because the classpath-variable has to exist before it can be modified. So creating it (by setting it to blank) in the server config solved the issue for me.

Sk4r
Obsidian | Level 7

@andreas_lds Thank you for your response, could you tell me, please, what steps did follow to set it properly? Just to avoid confusion. Thank you very much.

andreas_lds
Jade | Level 19

@Sk4r wrote:

@andreas_lds Thank you for your response, could you tell me, please, what steps did follow to set it properly? Just to avoid confusion. Thank you very much.


Just set an environment-variable on computer on which sas.exe is running. The process depends on the operating system used and is well documented. As value i used a single blank.

Sk4r
Obsidian | Level 7

Hi, I am using Windows 7, working on EG 7.1 and local machine, I'm following what this page says Ihttp://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#n0swy2q7eouj2fn11g1o...

 

I tried creating a new environment variable on Windows called CLASSPATH as a blank space and set its value on sas config file writing -SET CLASSPATH "route", but it didn't solve it.

If it wasn't bothersome, could you please tell your sources to do it, or how did you do it specifically, please? 

 

The error became a warning 

WARNING: Could not initialize classpath.  Classpath variable is not set.
path_separator=;
NOTE: Argumento no válido para la función SYSGET('CLASSPATH') en línea 77 columna 242. <--- This means argument no valid for the function sysget
NOTE: Ignore any messages from the next statement(s)
_ERROR_=1
orig_classpath= 
path_separator=; orig_classpath=  _ERROR_=1 _N_=1
andreas_lds
Jade | Level 19

I used the first option in the listed in the linked page:

Globally
Windows System Environment Variable in Control Panel
Control Panelthen selectSystemthen selectAdvancedthen selectEnvironment Variables (Windows XP Classic view)

 

You need to restart EG (all SAS processes).

Sk4r
Obsidian | Level 7

Thank you for your reply, I appreciate your time, it was holidays.

I created a new environment variable called CLASSPATH set as one blank space.

Then I follow the guide provided on the link to add a new path to the classpath.

After that, I run proc javainfo, but my path is not added to java.class.path, and errors about initializing classpath still occurs.

FS_TEMPLATE = C:\Program Files\SASHome\x86\SASFoundation\9.4\tkjava\sasmisc\qrpfstpt.xml
java.class.path = C:\PROGRA~1\SASHome\SASVER~1\eclipse\plugins\SASLAU~1.JAR

java.class.version = 51.0
java.runtime.name = Java(TM) SE Runtime Environment
java.runtime.version = 1.7.0_76-b13
java.security.auth.login.config = C:\Program
Files\SASHome\x86\SASFoundation\9.4\tkjava\sasmisc\sas.login.config
java.security.policy = C:\Program Files\SASHome\x86\SASFoundation\9.4\tkjava\sasmisc\sas.policy
java.specification.version = 1.7
java.system.class.loader = com.sas.app.AppClassLoader
java.vendor = Oracle Corporation
java.version = 1.7.0_76
java.vm.name = Java HotSpot(TM) Client VM
java.vm.specification.version = 1.7
java.vm.version = 24.76-b04
sas.app.class.path = C:\PROGRA~1\SASHome\SASVER~1\eclipse\plugins\tkjava.jar
sas.ext.config = C:\Program Files\SASHome\x86\SASFoundation\9.4\tkjava\sasmisc\sas.java.ext.config
sas.jre.libjvm = C:\PROGRA~1\SASHome\x86\SASPRI~1\9.4\jre\bin\client\jvm.dll
tkj.app.launch.config = C:\PROGRA~1\SASHome\SASVER~1\picklist
user.country = PE
user.language = es
andreas_lds
Jade | Level 19

Please post the code you used.

Sk4r
Obsidian | Level 7

First, I set environment variable as blank space.

Captura.PNG

Then, I used the code provided on the link https://support.sas.com/kb/38/518.html

 

%macro init_classpath_update;
	DATA _null_;
	    LENGTH  path_separator $ 2
	            orig_classpath $ 500;

	    DECLARE JavaObj f("java.io.File", "");
	    f.getStaticStringField("pathSeparator", path_separator);

	    orig_classpath = STRIP(SYSGET("CLASSPATH"));

	    IF _ERROR_ = 1 OR LENGTH(orig_classpath) = 0 THEN DO;
			PUT "NOTE: Ignore any messages from the next statement(s)";
	        orig_classpath = "";
		END;

	    CALL SYMPUTX('CP_orig_classpath', STRIP(orig_classpath), 'GLOBAL');
	    CALL SYMPUTX('CP_path_separator', COMPRESS(path_separator), 'GLOBAL');
	RUN;
%mend;

%macro add_to_classpath(cp_addition);
	DATA _null_;
	    LENGTH  current_classpath $ 500
	            new_classpath $ 500;

	    current_classpath = STRIP(SYSGET("CLASSPATH"));

	    IF _ERROR_ = 1 OR LENGTH(current_classpath) = 0 THEN DO;
			PUT "NOTE: Ignore any messages from the nearby statement(s)";
	        new_classpath = "&cp_addition";
		END;
	    ELSE DO;
        	new_classpath = COMPRESS(current_classpath) || "&CP_path_separator" || "&cp_addition";
		END;

	    CALL SYMPUTX('CP_new_classpath', STRIP(new_classpath), 'GLOBAL');
	RUN;

	%PUT NOTE: Setting Java classpath to &CP_new_classpath;
	OPTIONS SET=CLASSPATH "&CP_new_classpath";
%mend;

%macro reset_classpath;
	%PUT NOTE: Setting Java classpath back to its original state: &CP_orig_classpath;
	OPTIONS SET=CLASSPATH "&CP_orig_classpath";
%mend;
/*Set path*/%init_classpath_update;
%add_to_classpath(V:\estadística\fuente\Java\Libreria);

/*Some javaobj code*/
%macro crea_directorio(path);
   data crea_directorio;
   declare javaobj jd;
   jd = _new_ javaobj ('Directorio',&path);
   jd.callBooleanMethod ('creaDir', rc);
   put 'rc: 1-|El directorio se creo, 0-| El directorio no se creo';
   put rc=;
   jd.delete();
   run;
%mend;

/*Some calls to the macro that uses javaobj*/

%reset_classpath;

is it maybe because the route contains characters that are not ASCII symbols?

 

andreas_lds
Jade | Level 19

is it maybe because the route contains characters that are not ASCII symbols?

Maybe. But more likely the problem is

%add_to_classpath(V:\estadística\fuente\Java\Libreria);

Are there classes or jars in the folder? If you have jars, you need to add every jar with %add_to_classpath.

Sk4r
Obsidian | Level 7

Thank you for your answer, it's a directory with classes, there are no jar files, just like the photo displays below.

Captura.PNG

andreas_lds
Jade | Level 19

Well, i don't get it. Extending CLASSPATH the way you did it should make those classes usable in sas. I am sorry, but i don't have any idea how to fix the problem. You should talk to tech support, i am sure they can find a solution.

Sk4r
Obsidian | Level 7

Well, It's only happening on my computer. I tried the program on another user who uses those java objects, and it runs correctly, while I'm just testing some things that doesn't concern too much on that.

 

Anyways, thank you for everything.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 5468 views
  • 0 likes
  • 2 in conversation