<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Parse special characters from REST API response in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726155#M225645</link>
    <description>&lt;P&gt;What is the encoding of your SAS session?&lt;/P&gt;
&lt;P&gt;What exactly doesn't work? Give more details please.&lt;/P&gt;
&lt;P&gt;Where does the process break? Are the contents of file LCODE valid? What about file LCODE1?&lt;/P&gt;</description>
    <pubDate>Sun, 14 Mar 2021 22:03:04 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-03-14T22:03:04Z</dc:date>
    <item>
      <title>Parse special characters from REST API response</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726151#M225643</link>
      <description>&lt;P&gt;Dear SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am fairly new to SAS and am currently running into some issues with the response from a Get call made to a REST API. Specifically, I am having issues parsing the Scandinavian letters 'æ, ø, å'. This code runs in Data Integration Studio in a UWC transformation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename lcode temp encoding="wlatin1";
filename lcode1 temp encoding="utf-8";

/*Make Get Call*/
%macro getResp();

	proc http 
		url="https://fakepath/response"
 		method="GET"
	   out=lcode;

	   headers 
			'Content-Type' = 'application/json' 
         'Accept' = 'application/json'
    		'Authorization' = "Bearer &amp;amp;access_token.";
		run;

	 data _null_;
      infile lcode;
      file lcode1;
      input;
      put _infile_;
   run;


	%parseRoot();
	%parseRespType();

%mend;

/*Macro to parse root*/
%macro parseRoot();
	
	libname resp json fileref=lcode1;

	data temp1;
			set resp.Root;
	run;

%mend;

%macro parseRespType();	

	libname resp json fileref=lcode1;

	data temp2;
			set resp.RespType;
			where RespTypeName Like 'LCD%';
	run;

%mend;


%getResp();

/*Join respons from REST API*/
proc sql;
	CREATE TABLE &amp;amp;_output1 as
	SELECT RespName, RespValue
	FROM temp1 as t1 inner join temp2 as t2
	ON t1.ordinal_root = t2.ordinal_root
	ORDER BY RespName;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code runs successfully and I receive the data as expected with the exception of words containing 'æ, ø, å' (e.g., løft -&amp;gt;&amp;nbsp;lÃ¸ft). The reason why I've set up the code in the manner which I have is that I based this on the solution offered in this thread&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Encoding-when-reading-data-from-api/td-p/426050" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Encoding-when-reading-data-from-api/td-p/426050&lt;/A&gt;&amp;nbsp;which does not work for me. Beyond changing the session encoding, is there a way to work around this issue?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 20:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726151#M225643</guid>
      <dc:creator>larsc</dc:creator>
      <dc:date>2021-03-14T20:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Parse special characters from REST API response</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726155#M225645</link>
      <description>&lt;P&gt;What is the encoding of your SAS session?&lt;/P&gt;
&lt;P&gt;What exactly doesn't work? Give more details please.&lt;/P&gt;
&lt;P&gt;Where does the process break? Are the contents of file LCODE valid? What about file LCODE1?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 22:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726155#M225645</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-14T22:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Parse special characters from REST API response</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726219#M225660</link>
      <description>&lt;P&gt;Thanks for your reply Chris - I'll try to provide more details. Firstly, the encoding of my SAS session is &lt;STRONG&gt;Latin1.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue specifically was&amp;nbsp;&lt;STRONG&gt;parsing Scandinavian letters ('æ, ø, å')&amp;nbsp;&lt;/STRONG&gt;when getting data from a REST API. For instance, for the word &lt;STRONG&gt;'Løft'&lt;/STRONG&gt; the '&lt;STRONG&gt;ø&lt;/STRONG&gt;' character in DI studio gets converted to&amp;nbsp;&lt;STRONG&gt;'Ã¸f'.&amp;nbsp;&lt;/STRONG&gt;So, this is not what I want or expect - as ideally the letters 'æ, ø, å' would be preserved in words containing these letters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While typing out this reply I actually managed to get it to work; the solution was to set up the code in the following manner which is exactly like the solution offered in this thread&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Encoding-when-reading-data-from-api/td-p/426050" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Encoding-when-reading-data-from-api/td-p/426050&lt;/A&gt;&amp;nbsp;- previously I missed the first filename definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Workaround to parse special scandinavian characters*/
%let f_path = /fakepath./keyword.json;
filename lcode "&amp;amp;f_path";


/*Make Get Call*/
%macro getSugg();

	proc http 
		url="https://fakepath/constant"
 		method="GET"
	   out=lcode;

	   headers 
			'Content-Type' = 'application/json' 
         'Accept' = 'application/json'
    		'Authorization' = "Bearer &amp;amp;access_token.";
		run;

	%let f_path = /fakepath./keyword.json;
	filename lcode "&amp;amp;f_path" encoding = "utf-8";
				
	%let f_path = /fakepath/keyword1.json;
	filename lcode1 "&amp;amp;f_path" encoding="wlatin1";

	 data _null_;
      infile lcode;
      file lcode1;
      input;
      put _infile_;
   run;

	%parseRoot();
	%parseCONSTANTTYPE();

%mend;

/*Macro to parse root*/
%macro parseRoot();
	
	libname resp json fileref = lcode1;

	data temp1;
			set resp.Root;
	run;

%mend;

%macro parseCONSTANTTYPE();	

	libname resp json fileref = lcode1;

	data temp2;
			set resp.CONSTANTTYPE;
			where ConstantTypeName Like 'XYZ%';
	run;

%mend;


%getSugg();

/*Join respons from REST API*/
proc sql;
	CREATE TABLE &amp;amp;_output1 as
	SELECT ConstantTypeName, ConstantValue
	FROM temp1 as t1 inner join temp2 as t2
	ON t1.ordinal_root = t2.ordinal_root
	ORDER BY CConstantTypeName;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Big thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117666"&gt;@rudfaden&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 08:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-special-characters-from-REST-API-response/m-p/726219#M225660</guid>
      <dc:creator>larsc</dc:creator>
      <dc:date>2021-03-15T08:28:57Z</dc:date>
    </item>
  </channel>
</rss>

