SAS Code to get FB data through Proc Groovy

Reply
Occasional Contributor
Posts: 14

SAS Code to get FB data through Proc Groovy

Hi Team,

I try to fetch the data from Facebook through SAS code Which is given below. I took the help of Paper SAS379-2014. I am getting an Error like ERROR: The EXECUTE command failed. and there is no data fetch happened from Facebook.

Filename token "D:\Rajesh_sun\SMA_Code\FB\SGF\token.sas";

%include token;

data _null_;

  fname='fh';

  rc=filename(fname,'D:/Rajesh_sun/SMA_Code/FB/tmp/groovy.csv');

  if(rc=0 and fexist(fname)) then

    rc=fdelete(fname);

  rc=filename(fname);

run;

filename csv 'D:/Rajesh_sun/SMA_Code/FB/tmp/groovy.csv';

data _null_;

  file csv;

  put 'id,updated_time,message';

run;

filename headers 'D:/Rajesh_sun/SMA_Code/FB/tmp/headers.txt';

filename out "D:/Rajesh_sun/SMA_Code/FB/tmp/http.json";

data _null_;

  file headers;

  put "Authorization: OAuth &token";

run;

%macro pullpage();

%put TOPULL=&topull;

%if %length(&topull) ^= 0 %then %do;

proc http

  method="get"

  headerin=headers

  url="&topull."

  out=out

;

run;

proc groovy;

  /* http://repository.codehaus.org/org/codehaus/groovy/groovy-all/1.8.6/ */

  add classpath="C:/Groovy/embeddable/groovy-2.4.3.jar";

  exec "C:/Groovy/embeddable/json2csv.groovy";

quit;

%end;

%mend;

%macro puller();

%let topull=https://graph.facebook.com/v2.3/anniktechnology?fields=posts;

%do %while(%length(&topull) ^= 0);

  %pullpage;

%end;

%mend;

%puller;

data statuses;

    infile csv missover dsd firstobs=2 ;

    informat id $50. updated_str $24. message $400.;

    input id $ updated_str $ message $;

    updated_time = input(substr(updated_str,1,22)||':'||substr(updated_str,23), e8601dz.);

    format updated_time datetime20.;

    drop updated_str;

run;

Log information:

1785  Filename token "D:\Rajesh_sun\SMA_Code\FB\SGF\token.sas";

1786  %include token;

1788  /*

1788! http://blogs.sas.com/content/sascom/2013/12/12/how-to-import-twitter-tweets-in-sas-data-step

1788! -using-oauth-2-authentication-style/ */

1789

1790  data _null_;

1791    fname='fh';

1792    rc=filename(fname,'D:/Rajesh_sun/SMA_Code/FB/tmp/groovy.csv');

1793    if(rc=0 and fexist(fname)) then

1794      rc=fdelete(fname);

1795    rc=filename(fname);

1796  run;

NOTE: DATA statement used (Total process time):

      real time          0.00 seconds

      cpu time            0.00 seconds

1797  filename csv 'D:/Rajesh_sun/SMA_Code/FB/tmp/groovy.csv';

1798  data _null_;

1799    file csv;

1800    put 'id,updated_time,message';

1801  run;

NOTE: The file CSV is:

      Filename=D:\Rajesh_sun\SMA_Code\FB\tmp\groovy.csv,

      RECFM=V,LRECL=32767,File Size (bytes)=0,

      Last Modified=03Jul2015:18:53:03,

      Create Time=03Jul2015:17:14:49

NOTE: 1 record was written to the file CSV.

      The minimum record length was 23.

      The maximum record length was 23.

NOTE: DATA statement used (Total process time):

      real time          0.01 seconds

      cpu time            0.00 seconds

1802

1803  filename headers 'D:/Rajesh_sun/SMA_Code/FB/tmp/headers.txt';

1804  filename out "D:/Rajesh_sun/SMA_Code/FB/tmp/http.json";

1805  data _null_;

1806    file headers;

1807    put "Authorization: OAuth &token";

1808  run;

NOTE: The file HEADERS is:

      Filename=D:\Rajesh_sun\SMA_Code\FB\tmp\headers.txt,

      RECFM=V,LRECL=32767,File Size (bytes)=0,

      Last Modified=03Jul2015:18:53:03,

      Create Time=03Jul2015:17:14:49

NOTE: 1 record was written to the file HEADERS.

      The minimum record length was 252.

      The maximum record length was 252.

NOTE: DATA statement used (Total process time):

      real time          0.00 seconds

      cpu time            0.00 seconds

1809

1810  %macro pullpage();

1811  %put TOPULL=&topull;

1812  %if %length(&topull) ^= 0 %then %do;

1813  proc http

1814    method="get"

1815    headerin=headers

1816    url="&topull."

1817    out=out

1818  ;

1819  run;

1820  proc groovy;

1821    /* http://repository.codehaus.org/org/codehaus/groovy/groovy-all/1.8.6/ */

1822    add classpath="C:/Groovy/embeddable/groovy-2.4.3.jar";

1823    exec "C:/Groovy/embeddable/json2csv.groovy";

1824  quit;

1825  %end;

1826  %mend;

1827  %macro puller();

1828  %let topull=https://graph.facebook.com/v2.3/anniktechnology?fields=posts;

1829  %do %while(%length(&topull) ^= 0);

1830    %pullpage;

1831  %end;

1832  %mend;

1833  %puller;

TOPULL=https://graph.facebook.com/v2.3/anniktechnology?fields=posts

NOTE: PROCEDURE HTTP used (Total process time):

      real time          1.63 seconds

      cpu time            0.00 seconds

NOTE: The ADD CLASSPATH command completed.

ERROR: The EXECUTE command failed.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

C:\Groovy\embeddable\json2csv.groovy: 3: unable to resolve class JsonSlurper

@ line 3, column

10.

  def json=new JsonSlurper().parseText(input)

            ^

1 error

    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:748)

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE GROOVY used (Total process time):

      real time          0.01 seconds

      cpu time            0.00 seconds

TOPULL=https://graph.facebook.com/v2.3/anniktechnology?fields=posts

NOTE: PROCEDURE HTTP used (Total process time):

      real time          1.63 seconds

      cpu time            0.04 seconds

NOTE: The ADD CLASSPATH command completed.

ERROR: The EXECUTE command failed.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

C:\Groovy\embeddable\json2csv.groovy: 3: unable to resolve class JsonSlurper

@ line 3, column

10.

  def json=new JsonSlurper().parseText(input)

            ^

1 error

    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:748)

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE GROOVY used (Total process time):

      real time          0.01 seconds

      cpu time            0.01 seconds

TOPULL=https://graph.facebook.com/v2.3/anniktechnology?fields=posts

NOTE: PROCEDURE HTTP used (Total process time):

      real time          1.43 seconds

      cpu time            0.00 seconds

NOTE: The ADD CLASSPATH command completed.

ERROR: The EXECUTE command failed.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

C:\Groovy\embeddable\json2csv.groovy: 3: unable to resolve class JsonSlurper

@ line 3, column

10.

  def json=new JsonSlurper().parseText(input)

            ^

1 error

    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:748)

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE GROOVY used (Total process time):

      real time          0.01 seconds

      cpu time            0.00 seconds

TOPULL=https://graph.facebook.com/v2.3/anniktechnology?fields=posts

NOTE: PROCEDURE HTTP used (Total process time):

      real time          4.89 seconds

      cpu time            0.00 seconds

Ask a Question
Discussion stats
  • 0 replies
  • 220 views
  • 0 likes
  • 1 in conversation