Last active
September 29, 2015 15:56
-
-
Save mathiasleroy/f22face83d696b45c17a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro pushFirebase(dataset,firebaseName,fbObject,variables); | |
/* | |
! change temporaryFilePath to fit your environement | |
dataset = sas data set to push to firebase | |
firebaseName = name of your firebase app name (xxx.firebaseio.com) | |
fbObject = name of the firebase object to create | |
variables = list of variables to include, separated by dashes (-) | |
*/ | |
/* CONSTANTS */ | |
%let temporaryFilePath = \\sas9xbi\Data2\tmp\; | |
/* VARIABLES */ | |
%let firebaseURL = https://&firebaseName..firebaseio.com/; | |
%let fileName = &fbObject..json; | |
%let variablesLength = %sysfunc(count(&variables,-)); | |
/******************************************************************** | |
CREATE JSON OBJECT | |
********************************************************************/ | |
data _null_; | |
set &dataset nobs=nobs end=end; | |
file "&temporaryFilePath.&fileName"; | |
if _n_=1 then put '{'; | |
put '"' %scan(&variables,1,-) +(-1) '":{'; | |
%do i = 1 %to &variablesLength+1; | |
variable = %sysfunc(strip("%scan(&variables,&i,-)")); | |
*this is a repetition, but it makes json cleaner; | |
if (&i ne 1) then put ',"' variable +(-1) '":' %scan(&variables,&i,-) ; | |
else put '"' variable +(-1) '":' %scan(&variables,&i,-) ; | |
%end; | |
put '}'; | |
if not end then do; | |
put ','; | |
end; | |
if end then do; | |
put '}'; | |
end; | |
run; | |
/******************************************************************** | |
PUSH TO FIREBASE | |
********************************************************************/ | |
filename resp TEMP; | |
filename headout TEMP; | |
filename input "&temporaryFilePath.&fileName"; | |
proc http | |
method="PUT" | |
url="&firebaseURL.&fileName" | |
in=input | |
out=resp | |
headerout=headout | |
;run; | |
%mend; | |
%pushFirebase(xxx.xxx,xxx,xxx,xxx-xxx-xxx-xxx); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment