BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal
Calcite | Level 5 Bal
Calcite | Level 5

I'm trying to execute simple json-xml convert program by using Proc Groovy which I found in Google to practice but getting error.

Below the code and log. Please let me know where i need to change my code. When I paste the code "import" shows in red letter in sas EG 7.1(Linux) not sure what's the issue.

22 GOPTIONS ACCESSIBLE;
23 /* using groovy to parse json into sas */


24 proc
24 ! groovy;
25
26
26 ! add classpath="java-json.jar";
NOTE: The ADD CLASSPATH command completed.
27
28 /* showing proc groovy where my json java files are */
29
29 ! submit;
29 ! /* starting groovy */
30
31 import org.json.JSONObject
32 import org.json.XML
33 import java.io.File
34 import java.io.PrintWriter
35
36 /* loading json from file */
37 def json_string = new File(".../test.json").text
38
39 /* converting json to xml */
40 def json = new JSONObject(json_string)
41 def xml = XML.toString(json)
42
43 /* saving to file */
44 def out = new PrintWriter(".../output_xml.xml")
45
46 /* adding xml headers */
47 out.println("<xml>", xml, "</xml>")
48
49 out.close()
50
2 The SAS System 08:36 Monday, September 26, 2016

51 endsubmit;
ERROR: The SUBMIT command failed.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script17.groovy: 2: unable to resolve class org.json.JSONObject
@ line 2, column 9.
import org.json.JSONObject
^

Script17.groovy: 3: unable to resolve class org.json.XML
@ line 3, column 3.
import org.json.XML
^

2 errors

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:860)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:521)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:497)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:474)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:292)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
52 quit;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE GROOVY used (Total process time):
real time 0.03 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 30.84k
OS Memory 16544.00k
Timestamp 09/26/2016 12:00:32 PM
Step Count 53 Switch Count 194
Page Faults 0
Page Reclaims 7
Page Swaps 0
Voluntary Context Switches 927
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

SAS will not make any syntax check on the groovy code. As mentioned earlier, I would check whether the class that is not found is in the jar file you mention

 

Bruno

View solution in original post

9 REPLIES 9
Bal
Calcite | Level 5 Bal
Calcite | Level 5
BrunoMueller
SAS Super FREQ

Hi

 

Try with the complete pathname for the ADD CLASSPATH statement.

 

Something like:

  add path="C:\Program Files\SASHome\SASVersionedJarRepository\eclipse\plugins\groovy_2.3.7.0_SAS_20151104171452\groovy-all.jar";

Bruno

Bal
Calcite | Level 5 Bal
Calcite | Level 5
I don't see any path "C:\..." for SAS in my directory. I'm on Linux box. Not sure how can i find groovy-all.jar location. Instead i have download *.jar file in my folder and define add path as this location but still same error.
Any suggestions?
BrunoMueller
SAS Super FREQ

SAS needs to find the jar file. So it has to be on the system where the SAS program runs. You need to specify the appropriate path.

 

You are talking about the "my folder", are you using the SAS University Edition?

 

Posting the log will help.

 

Bruno

Bal
Calcite | Level 5 Bal
Calcite | Level 5

I don't know how to find that jar location.
I'm using licensed SAS.

Log:

1 The SAS System 14:30 Tuesday, September 27, 2016

NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
NOTE: Copyright (c) 2002-2012 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M2)
NOTE: This session is executing on the Linux 2.6.32-573.22.1.el6.x86_64 (LIN X64) platform.



NOTE: Updated analytical products:

SAS/STAT 13.2
SAS/ETS 13.2
SAS/OR 13.2
SAS/IML 13.2

NOTE: Additional host information:

Linux LIN X64 2.6.32-573.22.1.el6.x86_64 #1 SMP Thu Mar 17 03:23:39 EDT 2016 x86_64 Red Hat Enterprise Linux Server release 6.7
(Santiago)

You are running SAS 9. Some SAS 8 files will be automatically converted
by the V9 engine; others are incompatible. Please see
http://support.sas.com/rnd/migration/planning/platform/64bit.html

PROC MIGRATE will preserve current SAS file attributes and is
recommended for converting all your SAS libraries from any
SAS 8 release to SAS 9. For details and examples, please see
http://support.sas.com/rnd/migration/index.html


This message is contained in the SAS news file, and is presented upon
initialization. Edit the file "news" in the "misc/base" directory to
display site-specific news and information in the program log.
The command line option "-nonews" will prevent this display.




NOTE: SAS initialization used:
real time 0.07 seconds
user cpu time 0.01 seconds
system cpu time 0.02 seconds
memory 3664.09k
OS Memory 4504.00k
Timestamp 09/27/2016 02:30:01 PM
Step Count 0 Switch Count 8
Page Faults 0
Page Reclaims 4186
Page Swaps 0
Voluntary Context Switches 257
Involuntary Context Switches 2
Block Input Operations 0
Block Output Operations 24

1 /* using groovy to parse json into sas */
2 proc
2 ! groovy;
2 The SAS System 14:30 Tuesday, September 27, 2016

3
4
4 ! add classpath="/(company)/projects/dev/ucf/bal/groovy-all-2.3.7-groovydoc.jar";
NOTE: The ADD CLASSPATH command completed.
5
6 /* showing proc groovy where my json java files are */
7
7 ! submit;
7 ! /* starting groovy */
8
9 import org.json.JSONObject
10 import org.json.XML
11 import java.io.File
12 import java.io.PrintWriter
13
14 /* loading json from file */
15 def json_string = new File("/(company)/projects/dev/ucf/bal/test.json").text
16
17 /* converting json to xml */
18 def json = new JSONObject(json_string)
19 def xml = XML.toString(json)
20
21 /* saving to file */
22 def out = new PrintWriter("/(company)/projects/dev/ucf/bal/output_xml.xml")
23
24 /* adding xml headers */
25 out.println("<xml>", xml, "</xml>")
26
27 out.close()
28
29 endsubmit;
ERROR: The SUBMIT command failed.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unable to resolve class org.json.JSONObject
@ line 2, column 9.
import org.json.JSONObject
^

Script1.groovy: 3: unable to resolve class org.json.XML
@ line 3, column 3.
import org.json.XML
^

2 errors

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:860)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:521)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:497)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:474)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:292)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
30 quit;

NOTE: The SAS System stopped processing this step because of errors.
3 The SAS System 14:30 Tuesday, September 27, 2016

NOTE: PROCEDURE GROOVY used (Total process time):
real time 1.54 seconds
user cpu time 0.00 seconds
system cpu time 0.01 seconds
memory 79.78k
OS Memory 4504.00k
Timestamp 09/27/2016 02:30:03 PM
Step Count 1 Switch Count 0
Page Faults 0
Page Reclaims 106
Page Swaps 0
Voluntary Context Switches 557
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0


ERROR: Errors printed on page 2.

NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
real time 1.63 seconds
user cpu time 0.02 seconds
system cpu time 0.03 seconds
memory 3845.90k
OS Memory 4504.00k
Timestamp 09/27/2016 02:30:03 PM
Step Count 1 Switch Count 10
Page Faults 0
Page Reclaims 4542
Page Swaps 0
Voluntary Context Switches 843
Involuntary Context Switches 2
Block Input Operations 0
Block Output Operations 40

BrunoMueller
SAS Super FREQ

From the message it looks like it can not find the class org.json.JSONObject. Are you sure this class is in the jar file you add?

 

Bruno

Bal
Calcite | Level 5 Bal
Calcite | Level 5
SAS editor red out 'import' statement when i typed, so my guess is something wrong with this statement?
BrunoMueller
SAS Super FREQ

SAS will not make any syntax check on the groovy code. As mentioned earlier, I would check whether the class that is not found is in the jar file you mention

 

Bruno

Bal
Calcite | Level 5 Bal
Calcite | Level 5

Thank you. Yes, i figured our class was not in jar file.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 5022 views
  • 0 likes
  • 2 in conversation