I am attempting to execute a macro from inside a data step. It is building the execution string as I would expect until I get to the part of needing to provide a JSON string to the final parameter.
%let execstr="listID=&listID,logpath=&logpath,token=&q_token,contacts=";
%put &=execstr;
data cconts;
set work.qcontacts;
call execute('%qualtrics_createcontacts('||&execstr||%nrstr('%BQUOTE%(')||jsonstr||%nrstr('%)%)'));
run;
The results of this in the log show that BQUOTE is not included, the closing paren is not included. I am not sure how to finish it off. Here is the log results so you understand what I mean.
WARNING: Apparent invocation of macro QUALTRICS_CREATECONTACTS not resolved.
WARNING: Apparent invocation of macro QUALTRICS_CREATECONTACTS not resolved.
NOTE: Line generated by the CALL EXECUTE routine.
1 + %qualtrics_createcontacts(listID=ML_5c3kFhBxk2MvSfP,logpath=/dcri/cdm/DEV/Qualtrics,token=rCjSeE0WKHIMwaTzC7GA7BKhJRW9Rs
_
180
1 !+opxxEGRqFK,contacts={"firstName":"198242","lastName":"103","extRef":"118415"}
ERROR 180-322: Statement is not valid or it is used out of proper order.
2 +
3 + %)%)
4 +
%qualtrics_createcontacts(listID=ML_5c3kFhBxk2MvSfP,logpath=/dcri/cdm/DEV/Qualtrics,token=rCjSeE0WKHIMwaTzC7GA7BKhJRW9RsopxxEGRqFK,c
ontacts={"firstName":"198243","lastName":"103","extRef":"118414"}
How do I get the closing parenthesis in there? How do I make sure the jsonstr portion is handled and passed correctly?
Thank you!
I am attempting to execute a macro from inside a data step.
Actually you are trying to use a data step to use CALL EXECUTE to stack calls to a macro to execute after the data step has finished.
It is building the execution string as I would expect until I get to the part of needing to provide a JSON string to the final parameter.
Please provide example input values of the dataset variables: jsonstr
Please proved example of a working call to the macro for that value.
Your macro does not appear to have been defined, so even once you get the call syntax fixed you still need to figure out how to get the macro compiled.
You might also explain how the macro is going to use that input.
Try something like this so that the macro call and the %BQUOTE() call are pushed onto the stack to run after the data step instead of execution while the CALL EXECUTE statement is running.
call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&listID,logpath=&logpath,token=&q_token'
,',contacts=%nrstr(%BQUOTE(',jsonstr,'))'
,')'
));
It could be that easiest thing to do is just put the value of JSONSTR inside of single quotes so that the macro processor will ignore any & or % characters in the string. But we would need to see how that value is used in the macro body.
call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&listID,logpath=&logpath,token=&q_token'
,',contacts=',quote(trim(jsonstr),"'")
,')'
));
I am attempting to execute a macro from inside a data step.
Actually you are trying to use a data step to use CALL EXECUTE to stack calls to a macro to execute after the data step has finished.
It is building the execution string as I would expect until I get to the part of needing to provide a JSON string to the final parameter.
Please provide example input values of the dataset variables: jsonstr
Please proved example of a working call to the macro for that value.
Your macro does not appear to have been defined, so even once you get the call syntax fixed you still need to figure out how to get the macro compiled.
You might also explain how the macro is going to use that input.
Try something like this so that the macro call and the %BQUOTE() call are pushed onto the stack to run after the data step instead of execution while the CALL EXECUTE statement is running.
call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&listID,logpath=&logpath,token=&q_token'
,',contacts=%nrstr(%BQUOTE(',jsonstr,'))'
,')'
));
It could be that easiest thing to do is just put the value of JSONSTR inside of single quotes so that the macro processor will ignore any & or % characters in the string. But we would need to see how that value is used in the macro body.
call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&listID,logpath=&logpath,token=&q_token'
,',contacts=',quote(trim(jsonstr),"'")
,')'
));
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.