<?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: Macro for Retrieving API Data 2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567318#M159529</link>
    <description>For debugging this, first can you call the macro manually and make sure it works. &lt;BR /&gt;&lt;BR /&gt;This would be submitting:&lt;BR /&gt;&lt;BR /&gt;%query_rxClass_api(rxcui=someVAlue);&lt;BR /&gt;&lt;BR /&gt;And then check the macro_call_2 data set and ensure that the STR variable is being created correctly. I don't think you need the %nrstr() for this one as well so you can delete that and the extra brackets.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;str=catt('%Query_RxClass_API(rxcui=',rxcui, ');');</description>
    <pubDate>Wed, 19 Jun 2019 15:23:12 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-06-19T15:23:12Z</dc:date>
    <item>
      <title>Macro for Retrieving API Data 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567308#M159523</link>
      <description>&lt;P&gt;I asked a very similar question yesterday here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Macro-to-Retrieve-API-Data/m-p/567064#M159422" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Macro-to-Retrieve-API-Data/m-p/567064#M159422&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having an almost identical issue with another macro, but can't seem to apply the solution that was provided to me yesterday.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rxcui;
input rxcui $7.;
datalines;
1551300
1551306
1745108
2058877
358925
;
run;

%macro Query_RxClass_API(rxcui=);
filename resp2 'location/demo2.json';
options SSLCALISTLOC="location/trustedcerts.pem";

proc http
method="GET"
url="https://rxnav.nlm.nih.gov/REST/rxclass/class/byRxcui.json?rxcui=&amp;amp;rxcui&amp;amp;relaSource=ATC"
out=resp2;
run;

libname myfiles2 json 'location/demo2.json';

%_eg_conditional_dropds(WORK.atcdata);
data atcdata;
set myfiles2.rxclassdruginfo_rxclassminconc;
rxcui=&amp;amp;rxcui;
run;

%if %sysfunc(exist(myfiles2.RXCLASSDRUGINFO_MINCONCEPT))=1 %then %do;

data atcdata2;
set myfiles2.RXCLASSDRUGINFO_MINCONCEPT;
run;

proc sql;
create table allatcdata as
	select a.*,
		   b.rxcui as rxcui2,
		   b.name
	from atcdata a left join atcdata2 b on
		 (a.ordinal_rxclassDrugInfo=b.ordinal_rxclassDrugInfo)
;
quit;

proc append base=support.rxcui_to_atc data=allatcdata force;
run;


%end;

%else %do;
proc append base=support.rxcui_to_atc data=atcdata force;
run;
%end;

%mend Query_RxClass_API;

data macro_call_2;
set rxcuis;

str=catt('%Query_RxClass_API(rxcui=',rxcui, ');');

call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried to use the function described yesterday, but was unable to get that to work.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data macro_call_2;
set rxcuis;

str=catt('%nrstr(%Query_RxClass_API(rxcui=',rxcui, '));');

call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yesterday the solver said I was running into "macro timing issues". If you are able to expand upon what is happening here so that I can hopefully understand future problems like this better I would appreciate it.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567308#M159523</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-06-19T14:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Retrieving API Data 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567318#M159529</link>
      <description>For debugging this, first can you call the macro manually and make sure it works. &lt;BR /&gt;&lt;BR /&gt;This would be submitting:&lt;BR /&gt;&lt;BR /&gt;%query_rxClass_api(rxcui=someVAlue);&lt;BR /&gt;&lt;BR /&gt;And then check the macro_call_2 data set and ensure that the STR variable is being created correctly. I don't think you need the %nrstr() for this one as well so you can delete that and the extra brackets.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;str=catt('%Query_RxClass_API(rxcui=',rxcui, ');');</description>
      <pubDate>Wed, 19 Jun 2019 15:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567318#M159529</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-19T15:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Retrieving API Data 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567372#M159544</link>
      <description>&lt;P&gt;Thank you for the tip. I was able to figure out what I was doing wrong, I think I did still need that function for it to work. Working macro below for any who are interested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: A little elaboration on the issue. I was assuming that one of the two datasets I was pulling from the API would always exist, which was false and was causing my logic to break. I then needed to use the same function from my linked example to call the macro successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Query_RxClass_API(rxcui=);
filename resp2 'location/demo2.json';
options SSLCALISTLOC="location/trustedcerts.pem";

proc http
method="GET"
url="https://rxnav.nlm.nih.gov/REST/rxclass/class/byRxcui.json?rxcui=&amp;amp;rxcui&amp;amp;relaSource=ATC"
out=resp2;
run;

libname myfiles2 json '/location/demo2.json';

%if %sysfunc(exist(myfiles2.rxclassdruginfo_rxclassminconc))=1 and %sysfunc(exist(myfiles2.RXCLASSDRUGINFO_MINCONCEPT))=1 
%then %do;

%_eg_conditional_dropds(WORK.atcdata);
data atcdata;
set myfiles2.rxclassdruginfo_rxclassminconc;
rxcui=&amp;amp;rxcui;
run;

data atcdata2;
set myfiles2.RXCLASSDRUGINFO_MINCONCEPT;
run;

proc sql;
create table allatcdata as
	select a.*,
		   b.rxcui as rxcui2,
		   b.name
	from atcdata a left join atcdata2 b on
		 (a.ordinal_rxclassDrugInfo=b.ordinal_rxclassDrugInfo)
;
quit;

proc append base=support.rxcui_to_atc data=allatcdata force;
run;
%end;

%if %sysfunc(exist(myfiles2.rxclassdruginfo_rxclassminconc))=1 and %sysfunc(exist(myfiles2.RXCLASSDRUGINFO_MINCONCEPT))=0 
%then %do;

%_eg_conditional_dropds(WORK.atcdata);
data atcdata;
set myfiles2.rxclassdruginfo_rxclassminconc;
rxcui=&amp;amp;rxcui;
run;

proc append base=support.rxcui_to_atc data=atcdata force;
run;
%end;

%else %do;

%end;
%mend Query_RxClass_API;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data macro_call_2;
set rxcuis;

str=catt('%nrstr(%Query_RxClass_API(rxcui=',rxcui, '));');

call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 17:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Retrieving-API-Data-2/m-p/567372#M159544</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-06-19T17:51:53Z</dc:date>
    </item>
  </channel>
</rss>

