Exploring, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

How to import Google Analytics data into SAS?

Reply
New Contributor
Posts: 3

How to import Google Analytics data into SAS?

Hi,

 

I am new to SAS and want to import data from Google Analytics.

 

I am following the post (https://blogs.sas.com/content/sasdummy/2017/04/14/using-sas-to-access-google-analytics-apis/) to import Google Analytics data with SAS. The version I use is SAS 9.4

 

But, I got an error (NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.) on the code below. Any Advise?

 

proc http
/* put this all on one line! */
 url="&oauth2.?client_id=&client_id.%str(&)code=&code_given.%str(&)client_secret=&client_secret.%str(&)redirect_uri=urn:ietf:wg:oauth:2.0:oob%str(&)grant_type=authorization_code%str(&)response_type=token"
 method="POST"
 out=token
;
run;

 

SAS Super FREQ
Posts: 322

Re: How to import Google Analytics data into SAS?

Are you using SAS Visual Analytics? In VA 7.2 and later you can import data from Google Analytics through the UI:

https://support.sas.com/documentation/cdl/en/vaug/68027/HTML/default/viewer.htm#p1pfcz6uso42h4n13gnq...

 

 

Hope this helps,

Sam

New Contributor
Posts: 3

Re: How to import Google Analytics data into SAS?

Yes, I know I could use the UI. But, it has the limitation of fixed data size (once you've created the lasr table, you cannot add data to that table). What I want to achieve is that to make the lasr table (data source) grow such that my report linked to that data source could have up-to-date data. That's why I use the script to download the data into a staging table and then massage the data to the lasr table.

 

Am I doing it correctly? Any easier alternative?

Super User
Posts: 8,220

Re: How to import Google Analytics data into SAS?

Assuming you've set the 

oauth2

macro variable as shown in the example that @ChrisHemedinger provided, you could always try to run this line first:

options NOQUOTELENMAX;

Art, CEO, AnalystFinder.com

 

New Contributor
Posts: 3

Re: How to import Google Analytics data into SAS?

Thanks a lot. That resolves the error.

 

However, I receive another error "400 Bad Request". I think it's related to this line. When I ran the URL in a browser, it returns "Not Found". Any ideas?

 

%let oauth2=https://www.googleapis.com/oauth2/v4/token;

Here's the full code:

 

filename token "c:\temp\token.json";
%let code_given =<code-returned-from-step-1> ;
%let oauth2=https://www.googleapis.com/oauth2/v4/token;
%let client_id=<your-client-id>.apps.googleusercontent.com;
%let client_secret=<your-client-secret>;
proc http
 url="&oauth2.?client_id=&client_id.%str(&)code=&code_given.%str(&)client_secret=&client_secret.%str(&)redirect_uri=urn:ietf:wg:oauth:2.0:oob%str(&)grant_type=authorization_code%str(&)response_type=token"
 method="POST"
 out=token
;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 546 views
  • 1 like
  • 3 in conversation