BookmarkSubscribeRSS Feed
DevinChellberg
Fluorite | Level 6

I have a curl command that works in the command prompt that I need to get working in SAS 9.2. This is all translated from proc HTTP in 9.4 because some users at my company are still using the old version.

 

The command that works in the command prompt (with abc123 substituted in critical positions): 

C:\Users\dc2\Downloads\curl.exe --location --request POST "https://example.com" -H "Authorization:Basic abc123==" -H "Content-Type:application/x-www-form-urlencoded" -H "Cookie:abc123=abc123" --data-urlencode "grant_type=refresh_token" --data-urlencode "refresh_token=abc123" > "C:\token.json"

 

In SAS it looks like: 

 

data test;
	
	CURLText = 'C:\Users\dc2\Downloads\curl.exe --location --request POST "https://example.com" -H "Authorization:Basic abc123==" -H "Content-Type:application/x-www-form-urlencoded" -H "Cookie:abc123=abc123" --data-urlencode "grant_type=refresh_token" --data-urlencode "refresh_token=abc123" > "C:\token.json"';

	call symput ('CURLText', CURLText);
run;

filename req pipe %sysfunc(quote(&CURLText));

data _null_;
infile req missover lrecl= 32000;
input ;
file Response;
put _infile_;   
run;

Right now the error being stored in the local file is: Illegal character 'ᅠ' in header name. That error message goes away (and is replaced with an invalid request error) if I remove the colons from the header text.

 

I would appreciate any help getting this to work! Once I have it working in long form, I'll tackle storing some of the relevant bits in macro variables and referencing them within the filename statement.

 

Thanks!

 

10 REPLIES 10
japelin
Rhodochrosite | Level 12

How about this.

Try adding two single quotes, one at the beginning and one at the end.

 

CURLText = '''C:\Users\dc2\Downloads\curl.exe ..... =abc123" > "C:\token.json"''';
DevinChellberg
Fluorite | Level 6
That interpreted the outfile path as a single quote as part of the file type of the json (json'), returning an error of "The specified path is invalid" and not populating anything in the file.

Thanks for the suggestion!
DevinChellberg
Fluorite | Level 6
That returns the same error as my original code, "Illegal character ' ' in header name"

Thanks for the suggestion!
ChrisNZ
Tourmaline | Level 20

What happens if you quote in

call symput ('CURLText', quote(trim(CURLText)));

rather than in the filename?   

 

DevinChellberg
Fluorite | Level 6
No difference, unfortunately. Good idea to try it though!
Ksharp
Super User
Did you try X command ?

x 'C:\Users\dc2\Downloads\curl.exe --location --request POST "https://example.com" -H "Authorization:Basic abc123==" -H "Content-Type:application/x-www-form-urlencoded" -H "Cookie:abc123=abc123" --data-urlencode "grant_type=refresh_token" --data-urlencode "refresh_token=abc123" > "C:\token.json" ';
DevinChellberg
Fluorite | Level 6
I have experimented with filename, x, %sysexec, call system. I've had the most luck with filename in terms of even getting error messages back.

When I run the above syntax with an x command, it doesn't appear to do anything at all: there is no output saved as the desired file location and the command prompt doesn't even flicker.

If that feels like something easier to fix, I'd love to hear any suggestions!
ChrisNZ
Tourmaline | Level 20

Can you show us the log please? I get a feeling that maybe the code is fine, and it's the returned data that trips SAS.

DevinChellberg
Fluorite | Level 6

You must have been on to something. When I restarted SAS overnight, it just works now. I've spent 3 days trying as many combinations of quotes as I can think of, and today it just works (using the syntax in the original post).

 

I hate it, lol.

 

Thanks everyone for your help!

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
  • 10 replies
  • 2865 views
  • 2 likes
  • 5 in conversation