<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Passing Dataset to Google Sheets API (Stuck using %include for .json file) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544844#M150687</link>
    <description>&lt;P&gt;Thanks for sharing your nice and clean complete code! I'm sure others will be able to reference it!&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2019 13:20:08 GMT</pubDate>
    <dc:creator>noling</dc:creator>
    <dc:date>2019-03-21T13:20:08Z</dc:date>
    <item>
      <title>Passing Dataset to Google Sheets API (Stuck using %include for .json file)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544542#M150606</link>
      <description>&lt;P&gt;I'm trying to create a macro that will take a SAS dataset as an input and upload it to Google Sheets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I am able to determine the amount of columns and rows needed, and convert the dataset into a JSONL file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This example code has been tested and works:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
  url="https://sheets.googleapis.com/v4/spreadsheets/&amp;amp;_spreadsheetID./values/Sheet1!A1:&amp;amp;_col.&amp;amp;_row.?valueInputOption=USER_ENTERED"
  method="PUT" out=gs_resp
  in="%bquote({
  "range": "Sheet1!A1:%superq(_col)%superq(_row)",
  "majorDimension": "ROWS",
  "values": [
    ["Item","Price","Stocked","Ship Date"],
	["Wheel","$20.50","4","3/1/2016"],
	["Door","$15","5","3/15/2016"],
	["Engine","$100","3","3/20/2012"],
	["Hood","$37.5","1","1/1/1900"]
  ],
})";
  headers
	"Authorization"="Bearer &amp;amp;access_token."
    "client-id:"="&amp;amp;client_id.";	
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I just need to replace the hard-coded values list with my JSONL file the macro generates. I've tried using %include but it won't execute (I'm assuming because I am trying to use it inside of a statement?) :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
  url="https://sheets.googleapis.com/v4/spreadsheets/&amp;amp;_spreadsheetID./values/Sheet1!A1:&amp;amp;_col.&amp;amp;_row.?valueInputOption=USER_ENTERED"
  method="PUT" out=gs_resp
  in="%bquote({
  "range": "Sheet1!A1:%superq(_col)%superq(_row)",
  "majorDimension": "ROWS",
  "values": [
   	%include '/some_path_to_a_json_file';
  ],
})";
  headers
	"Authorization"="Bearer &amp;amp;access_token."
    "client-id:"="&amp;amp;client_id.";	
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;These are the contents of the JSON file I'm trying to call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;["Item","Price","Stocked","Ship Date"],["Wheel","$20.50","4","3/1/2016"],["Door","$15","5","3/15/2016"],["Engine","$100","3","3/20/2012"],["Hood","$37.5","1","1/1/1900"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way around this, or a better way to do this? I've already tried storing the values list inside of a macro variable and then calling the macro variable, and this works, but only for small datasets. I wanted to be able to handle datasets with thousands of records, thus my attempt to convert the dataset into a JSONL file instead.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if there is already a better way to upload a SAS dataset to Google Sheets please point me in that direction and I will be eternally grateful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 13:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544542#M150606</guid>
      <dc:creator>adamdeluca870</dc:creator>
      <dc:date>2019-03-20T13:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Dataset to Google Sheets API (Stuck using %include for .json file)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544616#M150626</link>
      <description>&lt;P&gt;Can you write the entire contents of your IN options to an external file (including your data rows), then read in that file as a file ref for your IN option? I'm looking at this &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a003286808.htm" target="_self"&gt;example&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544616#M150626</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-03-20T15:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Dataset to Google Sheets API (Stuck using %include for .json file)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544843#M150686</link>
      <description>&lt;P&gt;Worked like a charm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For completeness, proc json can be used to easily convert the dataset into the correct format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc json out=json pretty nosastags nokeys;
	export &amp;amp;_libname..&amp;amp;_memname.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then the entire payload can be written to a text file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	file payload;
	infile json firstobs=2 end=eof;
	input;
	if _N_ = 1 then
		do;
			put '{';
			put '"range": "Sheet1!A1:'@;
			put "&amp;amp;_col.&amp;amp;_row."@;
			put '",';
			put '"majorDimension": "ROWS",';
			put '"values":[';
			put "%superq(_headers),";
		end;
	if eof then 
		do;
			put _infile_ @;
			put ',';
			put '}';
		end;
	else 
		do;
			put _infile_;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2019 13:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544843#M150686</guid>
      <dc:creator>adamdeluca870</dc:creator>
      <dc:date>2019-03-21T13:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Dataset to Google Sheets API (Stuck using %include for .json file)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544844#M150687</link>
      <description>&lt;P&gt;Thanks for sharing your nice and clean complete code! I'm sure others will be able to reference it!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 13:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Dataset-to-Google-Sheets-API-Stuck-using-include-for/m-p/544844#M150687</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-03-21T13:20:08Z</dc:date>
    </item>
  </channel>
</rss>

