I want to call proc http and pass in a string to the url which contains a variable like this (and call the macro from a data step):
%macro cool (macroCUI=);
proc http
headerout=
hdrout
method="GET"
out=outXML
url= catt( "http://xxx/REST/xxx/", ¯oCUI,"/yyy");
run;
%mend cool;
data temp;
set PIMTable1;
execute ('%cool(macroCUI='||cui ||')');
run;
However, this will get an error that the url variable is expecting a string.
I can create a macro like below, but the timing of the macro within a macro does not work. I will only ever get the last one in the data step.
macro cool (macroCUI=);
data _null_;
length url $ 2048;
url = catt( "http://xxxx/REST/xxxx/", ¯oCUI,"YYYY");
url = translate(trim(url), '+', ' ');
call symputx('REQUEST_URL', url);
run;
proc http
headerout=
hdrout
method="GET"
out=outXML
url= "%superq(REQUEST_URL)";
run;
data temp;
set PIMTable1;
execute ('%cool(macroCUI='||cui ||')');
run;
Any suggestions?
Your basic idea should work. A couple of suggested code changes:
1) You do not need a function to append strings in macro language. Just put them together.
url="http://xxx/REST/xxx/¯oCUI/yyy"
2) You need to use CALL EXECUTE and not just EXECUTE in the last data step.
You might need to use URLENCODE or HTMLENCODE function to get the string in the proper form. Try typing the PROC HTTP code manually until you get the proper syntax, then create the code to convert it. Some url's include '&' characters which can cause confusion for macro code unless quoted properly. You might want to add single quotes around it in the macro call to prevent this.
Does the input dataset PIMTable1 have more than one observation?
Are you expecting to run the PROC HTTP code multiple times overwriting the same output file?
%macro cool (str);
%local url ;
%* remove outer quotes ;
%let url=%qsysfunc(dequote(&str));
%* Add prefix, suffix and convert spaces to plus signs ;
%let url=%qsysfunc(translate(http://xxxx/REST/xxxx/&url/YYYY,+,%str( ))) ;
proc http
headerout= hdrout
method="GET"
out=outXML
url= %sysfunc(quote(&url))
;
run;
%mend cool;
data temp;
set PIMTable1;
call execute(cats('%cool(',"'",cui,"'",')'));
run;
Your basic idea should work. A couple of suggested code changes:
1) You do not need a function to append strings in macro language. Just put them together.
url="http://xxx/REST/xxx/¯oCUI/yyy"
2) You need to use CALL EXECUTE and not just EXECUTE in the last data step.
You might need to use URLENCODE or HTMLENCODE function to get the string in the proper form. Try typing the PROC HTTP code manually until you get the proper syntax, then create the code to convert it. Some url's include '&' characters which can cause confusion for macro code unless quoted properly. You might want to add single quotes around it in the macro call to prevent this.
Does the input dataset PIMTable1 have more than one observation?
Are you expecting to run the PROC HTTP code multiple times overwriting the same output file?
%macro cool (str);
%local url ;
%* remove outer quotes ;
%let url=%qsysfunc(dequote(&str));
%* Add prefix, suffix and convert spaces to plus signs ;
%let url=%qsysfunc(translate(http://xxxx/REST/xxxx/&url/YYYY,+,%str( ))) ;
proc http
headerout= hdrout
method="GET"
out=outXML
url= %sysfunc(quote(&url))
;
run;
%mend cool;
data temp;
set PIMTable1;
call execute(cats('%cool(',"'",cui,"'",')'));
run;
Thank you! Your tip #1 worked. I do have multiple observations in PIMTable, that I will pass in and call the proc http mutliple times with different URL values. Thanks again.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.