BookmarkSubscribeRSS Feed
GregSo
Calcite | Level 5

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;

 

4 REPLIES 4
Sam_SAS
SAS Employee

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

GregSo
Calcite | Level 5

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?

art297
Opal | Level 21

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

 

GregSo
Calcite | Level 5

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2303 views
  • 1 like
  • 3 in conversation