BookmarkSubscribeRSS Feed
carloshmcaldas
Fluorite | Level 6

I´ve been trying to use SAS to import a database extracted through curl, but couldn´t figure how to pass the --data statement.

 

My curl command is:

 

curl --data "format=csv&includeColumnHeaders=1" --header "X-RJM-API-Key: <my-api-key>" https://api.rjmetrics.com/0.1/figure/<my-table-id>/export --ssl-no-revoke

 

 

I´ve tryied proc http method, but without success.

Any suggestions?

6 REPLIES 6
AhmedAl_Attar
Ammonite | Level 13
Have you tried to save the output of the curl command to a file using the -o directive/flag, then using SAS to read in the saved csv file?
example: curl --data "format=csv&includeColumnHeaders=1" --header "X-RJM-API-Key: <my-api-key>" https://api.rjmetrics.com/0.1/figure/<my-table-id>/export --ssl-no-revoke -o somefilename.csv
ChrisHemedinger
Community Manager

Try something like this:

 

filename result "/path-to-new-csv.csv";
proc http
 url="https://api.rjmetrics.com/0.1/figure/<my-table-id>/export"
 in = "format=csv&includeColumnHeaders=1"
 out = result;
 
headers
 "X-RJM-API-Key" = "<my-api-key>";
run;

 

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
carloshmcaldas
Fluorite | Level 6

Tryed


filename result temp;
proc http
url="https://api.rjmetrics.com/0.1/figure/11111/export"
in = "format=csv"
in = "includeColumnHeaders=1"
out=result;
headers "X-RJM-API-Key" = "11111111";
debug level=3;
run;

Log shows a 403 error:

< HTTP/1.1 403 Forbidden
< Content-Type: text/html; charset=UTF-8
< Date: Thu, 03 Feb 2022 17:21:30 GMT
< Server: Apache
2 The SAS System 13:20 Thursday, February 3, 2022

< Content-Length: 13
< Connection: keep-alive


On my curl command I had to use "--ssl-no-revoke"

By the way, is there a way to make the output as a dataset, instead of a CSV?


Thanks Chris!

ChrisHemedinger
Community Manager

First, make sure you can get to the internet from your SAS session. Run this test. You might need to specify a proxy host.

 

For the SSL check, you might add this statement before the run;

sslparms "sslreqcert"="allow";

The SSLPARMS statement can help specify behavior for verifying certificates.

 

Oh, and as far as getting a data set instead -- quickest way is PROC IMPORT after your step:

proc import 
 datafile="path-to-csv-result.csv"
 out=work.result
 dbms=CSV;
run;

A DATA step is more flexible to read CSV, but requires you know something about its structure.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
carloshmcaldas
Fluorite | Level 6

I've tried sslreqcert and still dont works..

ChrisHemedinger
Community Manager

What error are you getting? The same HTTP 403?

 

Just noticed in the code you said you tried you had two IN= option specified. You need just one IN=, like this:

 

filename result temp;
proc http
url="https://api.rjmetrics.com/0.1/figure/11111/export"
in = "format=csv&includeColumnHeaders=1"
out=result;
headers "X-RJM-API-Key" = "11111111";
debug level=3;
run;

 

And did you test PROC HTTP in general as I suggested? Is that working?

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1095 views
  • 1 like
  • 3 in conversation