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
Rhodochrosite | Level 12
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;

 

 

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
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.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
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?

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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