<?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: How can I use macro variable reading API JSON in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557574#M155454</link>
    <description>&lt;P&gt;Hi Bill, thank you for your contact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried it on past without success. EG returned the error below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;EM&gt;ERROR: The tcpSockRead call failed. The system error is 'The connection was reset by a peer.'.&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;ERROR: Connection has been closed.​&lt;/EM&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still trying found a way to solve it.&amp;nbsp; Any new idea / tips / suggestion, will be very appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again,&lt;/P&gt;&lt;P&gt;TF&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2019 19:06:35 GMT</pubDate>
    <dc:creator>tfabri</dc:creator>
    <dc:date>2019-05-09T19:06:35Z</dc:date>
    <item>
      <title>How can I use macro variable reading API JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/555746#M154686</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to do a API requisition through EG but I have no success in my call. I've tested it in Postman and there it is working normally.&lt;/P&gt;&lt;P&gt;I need passing 6 fields variables on Body, then I think that's need using the PUT, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below there is my example, using only one field on body:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let val = "SMS2";

/* Put the body of the JSON content in external file */
filename json_in temp;
data _null_;
file json_in;
put;
put "{";
put '"Tp_SMS":'"&amp;amp;val.";
put "}";
run;


proc http
url="https://xxxxxxxxxxxxxx/xxxxx/xxxx/xxxxx"
method="POST"
ct="application/x-www-form-urlencoded"
in=json_in
    out=posta
headerout=hdrout;
headers
"Host"="xxxxxxx"
"Authorization"="bearer XXXXXXXXXXXXXX"  
"Content-Type"="application/json"
"Content-Length"="xxxxxxx"
"CD_Login"="xxxxxxx";
Run;&lt;/PRE&gt;&lt;P&gt;How can I solved it?&amp;nbsp; How I should add others fields varsiables on body - using PUT?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Important:&amp;nbsp; If I use the "Datalines" than "PUT",&amp;nbsp; with one field - I have success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be very appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tks,&lt;/P&gt;&lt;P&gt;TF&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 19:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/555746#M154686</guid>
      <dc:creator>tfabri</dc:creator>
      <dc:date>2019-05-02T19:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use macro variable reading API JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/555759#M154697</link>
      <description>&lt;P&gt;Please show the non-macro version using datalines that does work.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 20:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/555759#M154697</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-02T20:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use macro variable reading API JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/555762#M154699</link>
      <description>&lt;P&gt;I am not quite sure exactly what you need. But if you want a JSON file with the 6 fields, it might be easier (if you have SAS 9.4) to use the JSON procedure. Here is code I put together that I think creates the file you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc json out="./tfabri.json" pretty nosastags;
  write open object;
    write values "SMS2" "&amp;amp;val"; 
    write values "field_2" "field_2_value";
    /* Add the other 4 values */
  write close;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here are the contents of the file:&lt;/P&gt;
&lt;PRE&gt;{
  "SMS2": "SMS2",
  "field_2": "field_2_value"
}
&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 20:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/555762#M154699</guid>
      <dc:creator>BillM_SAS</dc:creator>
      <dc:date>2019-05-02T20:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use macro variable reading API JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557196#M155298</link>
      <description>&lt;P&gt;Hi Bill, thank you for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still working on this. With your suggestion I can create a JSON file, but when I tried to run HTTP PROC (using this JSON file) I was not successful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME JSON_IN TEMP;
PROC JSON OUT="C:\TEMP\TESTE_NOVO.JSON" PRETTY NOKEYS NOSASTAGS;
WRITE OPEN OBJECT;
WRITE VALUES "TP_SMS" "CCSMS"; 
WRITE VALUES "NM_REMETENTESMS" "TESTE";
WRITE VALUES "NR_TELEFONECELULARSMS" "1";
WRITE VALUES "TX_MENSAGEMSMS" "MSG";
WRITE VALUES "DT_PARAENVIOSMS" "1";
WRITE VALUES "DT_LIMITEENVIOSMS" "S";
WRITE VALUES "DS_CHAVEORIGEMSMS" "1";
WRITE CLOSE;
RUN;


FILENAME POSTA "C:\TEMP\POSTA.TXT";
PROC HTTP
URL="HTTPS://***********/*******/CORPO/SMS/INCLUISMS"
METHOD="POST"
CT="APPLICATION/X-WWW-FORM-URLENCODED" /*JSON" */
IN=JSON_IN
    OUT=POSTA;
HEADERS
"HOST"="*******"
"AUTHORIZATION"="BEARER &amp;amp;TOKEN"  
"CONTENT-TYPE"="APPLICATION/JSON"
"CONTENT-LENGTH"="**"
"CD_LOGIN"="******";
RUN;

%PUT HTTP STATUS CODE = &amp;amp;SYS_PROCHTTP_STATUS_CODE. : &amp;amp;SYS_PROCHTTP_STATUS_PHRASE.;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any additional suggestion?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;Tf&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557196#M155298</guid>
      <dc:creator>tfabri</dc:creator>
      <dc:date>2019-05-08T16:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use macro variable reading API JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557475#M155412</link>
      <description>&lt;P&gt;I am not a PROC HTTP expert but, I do not see how the JSON file you created in being used by the HTTP code based on what you posted. You are writing the JSON to the teste_novo.json file. The input for PROC HTTP is&amp;nbsp;specified as JSON_IN. The filename statement specifies JSON_IN as the TEMP device type. The TEMP device just creates a temporary file for the lifetime of the FILENAME statement. In the SAS code that you posted, I do not see how the JSON file gets placed into the JSON_IN temporary location. To use the JSON file you created, I think that the PROC HTTP statement needs to have the IN argument modified to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IN="C:\temp\teste_novo.json"&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 15:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557475#M155412</guid>
      <dc:creator>BillM_SAS</dc:creator>
      <dc:date>2019-05-09T15:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use macro variable reading API JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557574#M155454</link>
      <description>&lt;P&gt;Hi Bill, thank you for your contact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried it on past without success. EG returned the error below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;EM&gt;ERROR: The tcpSockRead call failed. The system error is 'The connection was reset by a peer.'.&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;ERROR: Connection has been closed.​&lt;/EM&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still trying found a way to solve it.&amp;nbsp; Any new idea / tips / suggestion, will be very appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again,&lt;/P&gt;&lt;P&gt;TF&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 19:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-use-macro-variable-reading-API-JSON/m-p/557574#M155454</guid>
      <dc:creator>tfabri</dc:creator>
      <dc:date>2019-05-09T19:06:35Z</dc:date>
    </item>
  </channel>
</rss>

