BookmarkSubscribeRSS Feed
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 "" -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 "" -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);

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

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

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.




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"''';
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!
Fluorite | Level 6
That returns the same error as my original code, "Illegal character ' ' in header name"

Thanks for the suggestion!
Tourmaline | Level 20

What happens if you quote in

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

rather than in the filename?   


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

x 'C:\Users\dc2\Downloads\curl.exe --location --request POST "" -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" ';
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!
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.

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!

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
  • 10 replies
  • 5 in conversation