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!
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"''';
Use single quotes around the command:
call symput ('CURLText',quote(CURLText,"'"));
and no quoting in the FILENAME:
filename req pipe CURLText;
What happens if you quote in
call symput ('CURLText', quote(trim(CURLText)));
rather than in the filename?
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.