Robert Penridge
Robert Penridge

Reputation: 8513

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?

Upvotes: 3

Views: 523

Answers (2)

Joe
Joe

Reputation: 63424

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;

Upvotes: 1

Robert Penridge
Robert Penridge

Reputation: 8513

According to the documentation (https://support.sas.com/documentation/cdl/en/ds2ref/68052/HTML/default/viewer.htm#n1w9ms65zrao57n1p1yt4029jcwt.htm) they use method overloading on createParser . There's 4 methods to choose from and it seems that somehow SAS can't tell which of the 4 I'm trying to call:

Form 1:

package.CREATEPARSER ( );

Form 2:

package.CREATEPARSER (json-text, tipping-size);

Form 3:

package.CREATEPARSER (json-text);

Form 4:

package.CREATEPARSER (tipping-size);

I found an ugly solution which is simply to call Form 2 in order to make the call unambiguous. I set the tipping point to 32767 as I'm working with data in SAS tables and none of the results will be longer than that anyway. Final code:

proc ds2;
  data want (overwrite=yes);

    dcl package json j();   
    dcl int rc;

    method init();
      set have; 
      rc = j.createParser( name , 32767 );
    end;

  enddata;
%runquit;

Upvotes: 1

Related Questions