This code work fine - except for encoding of special characters ÆØÅ (and others). How do I change the encoding to UTF-8?
*****
filename req "F:\SASNykredit\CURL-HTTP\HTTP trial\Datafiler\request.txt" ;
filename resp "F:\SASNykredit\CURL-HTTP\HTTP trial\Datafiler\response.txt" MOD termstr=CRLF;
filename binfile "F:\SASNykredit\CURL-HTTP\HTTP trial\Datafiler\testdata2.xlsx";
filename head "F:\SASNykredit\CURL-HTTP\HTTP trial\Datafiler\Header.txt" recfm=V;
%let _boundary=3fbd04f5-b1ed-4060-99b9-fca7ff59c113;
%let _cat=Fokuslisten;
%let _bankID=Pengeinstitut_Bank_1;
%let _publdate=%sysfunc(today(), yymmddd10.);
%let _expdate=%sysfunc(intnx(MONTH,%sysfunc(today(),8.),12,S),yymmddd10.);
%let _showndate=%sysfunc(intnx(DAY,%sysfunc(today(),8.),2,S),yymmddd10.);
%let _binname=%scan(%sysfunc(pathname(binfile)),-1,'\');
%let _title=%upcase(&sysuserid) TEST ÆØÅ &_publdate.;
%let _apikey=xxx;
%put &=_boundary &=_cat &=_publdate &=_expdate &=_title &=_binname;
%put &=_bankID &=_showdate &=_apikey;
/*** Fanger fejlkode fra PROC HTTP ***/
%macro prochttp_check_return(_exp_code);
%if %symexist(SYS_PROCHTTP_STATUS_CODE) ne 1 %then
%do;
%put ERROR: Expected &_exp_code., but a response was not received from the HTTP Procedure;
%end;
%else
%do;
%if &SYS_PROCHTTP_STATUS_CODE. ne &_exp_code. %then
%do;
%put ERROR: Expected &_exp_code., but received &SYS_PROCHTTP_STATUS_CODE.;
%put ERROR: &SYS_PROCHTTP_STATUS_PHRASE.;
%end;
%else
%do;
%put NOTE: Alt i orden, forventet returkode: &SYS_PROCHTTP_STATUS_CODE. &SYS_PROCHTTP_STATUS_PHRASE.;
%end;
%end;
%mend prochttp_check_return;
/*** HEADER fil ***/
data _null_;
file head;
put "Authorization: ApiKey &_apiKey.";
run;
/*** MULTIPART-FORM data ***/
data _null_;
file req termstr=CRLF;
put "--&_boundary.";
put 'Content-Disposition: form-data; name="BankId"';
put;
put "&_bankid";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="Category"';
put;
put "&_cat";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="Title"';
put;
put "&_title";
put 'Content-Disposition: form-data; name="ExpirationDate"';
put;
put "&_expdate";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="PublishDate"';
put;
put "&_publdate";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="ShownDate"';
put;
put "&_showndate";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="File"; filename='"&_binname.";
put 'Content-Type: application/octet-stream';
put;
run;
/*** Tilføjer binær fil ***/
data _null_;
file req mod recfm=n;
infile binfile recfm=n;
input c $CHAR1.;
put c $CHAR1. @@;
%_run(w);
/*** Afslutning ***/
data _null_;
file req mod termstr=CRLF;
put / "--&_boundary.--";
%_run(w);
proc http
/*URL="https://ptsv2.com/t/kommunikationsplatform/post"*/
URL="https://kp-tot-inte.immeo.net/api/reports/update"
METHOD="PUT"
HEADERIN=head
CT="multipart/form-data; boundary=&_boundary"
in=req
out=resp;
DEBUG Level=1;
*HEADERS "Authorization "=" ApiKey &_apikey.";
run;
%put &=sys_prochttp_status_code.;
%put &=sys_prochttp_status_phrase.;
%prochttp_check_return(200);
filename req clear;
filename resp clear;
filename binfile clear;
filename head clear;
You don't write what you are encoding from to. But my guess is that the file you are attempting to download is in uft-8 while SAS data is in wlatin.
If this is the case, the best option is to change the encoding from uft-8 to wlatin. You can do this using filename.
filename resp "C:\Temp\utf8file.txt" encoding='utf-8';
filename resp1 "C:\Temp\wlatinfile.txt" encoding='wlatin1';
data _null_;
infile resp;
file resp1;
input;
put _infile_;
run;
Hope it works
First of all it's an upload (a PUT method) - the job is to post a file on a webserver.
Second, I have tried the encoding option with the filename - SAS fails big time. The webserver is UTF-8 (I think). ÆØÅ posted from my program is not ÆØÅ when recieved on the webserver (but something strange). I somehow have to enconde (some of) the request-file as UTF-8 before I PUT it.
I still think it would work in reverse. Take a wlatin file and saving it as an utf-8 file.
It's a little hard to test, as I can not run the code you posted. Maybe you can make a minimal working example?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.