All,
Wondering what this error is trying to prompt me towards and how may I fix it.
Objective : Macro making API call and should receive ZIP file in response
Errors from Log:
ERROR: Libref IN is not assigned.
SAS CODE:
filename ProjResp "<MyFileName.zip>";
libname in json "<MyFileName.zip>";
PROC HTTP
URL = &URLDes.
Method = "get"
out = ProjResp;
headers "Authorization" = "Bearer &AccessToken.";
Run;
Proc Contents Data = in._all_;
Run;
%Mend;
Here's the code I was using, it doesn't work anymore because I think they've changed their naming conventions but the idea is the same I think. This was designed to download a ZIP file from Statistics Canada, store it into the work folder and then read it in. This also assumed that I knew the name of the file inside the ZIP file.
%let CANSIM=02820087;
/* create a name for our downloaded ZIP */
%let ziploc = %sysfunc(getoption(work))/&cansim.-eng.zip;
filename download "&ziploc";
/* Download the ZIP file from the Internet*/
proc http
method='GET'
url="http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/&cansim.-eng.zip"
out=download;
run;
filename inzip zip "&ziploc";
filename xl "%sysfunc(getoption(work))/&cansim.-eng-csv";
data _null_;
/* using member syntax here */
infile inzip(&cansim.-eng.csv)
lrecl=256 recfm=F length=length eof=eof unbuf;
file xl lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
proc import datafile=xl dbms=csv out=confirmed replace;guessingrows=1000000;
run;
Can you direct a JSON library to a ZIP file? I would think it would need to be pointed at the JSON file directly not the ZIP version. There is a ZIP connection as well to access to the text files directly.
libname in json "<MyFileName.zip>";
@Reeza ,
Would you recommend re-directing it to a txt file ? If yes, can you kindly point me to an example on how to identify/parse the different files that are captured in the response ?
filename ProjResp "<MyFileName.txt>";
libname in json "<MyFileName.txt>";
PROC HTTP
URL = &URLDes.
Method = "get"
out = ProjResp;
headers "Authorization" = "Bearer &AccessToken.";
Run;
I updated my script as shown above. However, the text file is not readable and am wondering if the normal json parse as follows will be sufficient ?
data want;
set in.root;
run;
Because, I am not sure, how I can separate the different files expected as part of the output. Can you offer a little more guidance or point me to an example. Would appreciate it.
Here's the code I was using, it doesn't work anymore because I think they've changed their naming conventions but the idea is the same I think. This was designed to download a ZIP file from Statistics Canada, store it into the work folder and then read it in. This also assumed that I knew the name of the file inside the ZIP file.
%let CANSIM=02820087;
/* create a name for our downloaded ZIP */
%let ziploc = %sysfunc(getoption(work))/&cansim.-eng.zip;
filename download "&ziploc";
/* Download the ZIP file from the Internet*/
proc http
method='GET'
url="http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/&cansim.-eng.zip"
out=download;
run;
filename inzip zip "&ziploc";
filename xl "%sysfunc(getoption(work))/&cansim.-eng-csv";
data _null_;
/* using member syntax here */
infile inzip(&cansim.-eng.csv)
lrecl=256 recfm=F length=length eof=eof unbuf;
file xl lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
proc import datafile=xl dbms=csv out=confirmed replace;guessingrows=1000000;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.