Robert Penridge Robert Penridge - 1 month ago 21
JSON Question

Error using DS2 and JSON package

I'm trying to parse out a JSON file using the JSON package provided for

proc ds2
in SAS9.3 Maintenance 3 as per Chris Hemedinger's blog post here:

http://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/

Everything seemed to be working fine until I restarted my SAS session and now I keep on getting the message:

ERROR: Compilation error.
ERROR: Line 883: Ambiguous method call for method createparser. Multiple method declarations
match the given argument list.


Line 883 (in this case) refers to the line that contains the
createParser
call. Here's some simplified code that can reproduce the error:

data have;
set sashelp.class;
run;

proc ds2;
data want;

dcl package json j();
dcl int rc;

method run();
set have;
rc = j.createParser( name );
end;

enddata;
run;
quit;


What am I doing wrong?

Joe Joe
Answer

I think you're right that this is a bug on SAS's part, and I don't see unfortunately a way to confirm to SAS that you're using method 3 and not method 4. Just declaring name as character doesn't suffice, for some reason. Bring up a ticket with SAS for this, I would suggest.

However, I think method 1 is better than method 2 here, given you don't really want to specify the tipping size. Just move this to INIT (where it belongs anyway) and use setparserinput, as is suggested in the documentation:

data have;
  set sashelp.class;
run;

proc ds2;
  data want;

    dcl package json j();   
    dcl double rc;
    method init();
      rc = j.createParser();
      j.setParserInput(name);
    end;

    method run();
      set have; 
    end;

  enddata;
run;
quit;

Additionally, it looks like the reason the example works is the character set argument. UTF-8 or Unicode will work (the latter won't actually work for other reasons but will not break for this reason), while WLatin1, ANSI, or ASCII will not. Apparently setting it as a UTF-8 character causes SAS to realize it's really character?

data have;
  set sashelp.class;
run;

proc ds2;
  data want(overwrite=yes);

    dcl package json j();   
    dcl char(50)  character set utf8 name;
    dcl double rc;
    method init();
      rc = j.createParser( name );
    end;

    method run();
      set have; 
    end;

  enddata;
run;
quit;
Comments