2
votes

I'm trying to use CURL with SAS 9.3. I got it working for normal webpages. However, when I try to use it with a URL with 'env', I get the following error message: 'env' is not recognized as an internal or external command, operable program or batch file. Is there some CURL function that I can use in a filename statement, so CURL will recognize 'env' as part of the URL? Also, I tried proc http, but couldn't get it to work with a proxy. This is why I started using CURL. Thanks very much for any suggestions.

SAS code:

%let url=%NRSTR(https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.option_contract%20WHERE%20symbol%3D'YHOO'&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys);

filename curl pipe "curl -K &url 2>&1";

data _null_;
  infile curl lrecl=32767;
  input;
  put _infile_;
run;
2
What are you executing this on - Windows or UNIX?Joe
I'm executing this on Windows 7.user3806824

2 Answers

2
votes

Yes I've hit this issue before and it took a while to figure out.

It turns out that you need to use a caret ^ to mask any ampsersand & characters whenever you process it through the command line pipe. Looking back at it now I have no idea how I figured it out...

Also - you need to use a lowercase -k I believe.

I cleaned it up a little and this worked fine for me:

%let query= %sysfunc(urlencode(SELECT * FROM yahoo.finance.option_contract WHERE symbol='YHOO'));
%let env  = %sysfunc(urlencode(store://datatables.org/alltableswithkeys));
%let url  = https://query.yahooapis.com/v1/public/yql?q=&query^%nrstr(&)diagnostics=true^%nrstr(&)env=&env;

filename curl pipe "d:\sasdev\common\bin\curl\curl.exe -k &url 2>&1";

data _null_;
  infile curl lrecl=32767;
  input;
  put _infile_;
run;

Note that you'll want to change the path to curl.

0
votes

I would try adding quotes that will get passed to Windows.

Something like

"curl -k ""&url."" 2>&1"

The doubled double quotes are passesd as a single " character to Windows.