0
votes

when using %STR([email protected];[email protected];[email protected]); This gives me the result: [email protected];[email protected];[email protected] which is what I want. and this is a macro variable called &email. I need this semicolon in between any two emails but no semicolon after the last email But for someone who has an single quote in her email address like O'Connor, %str will automatically match the single quote using %STR([email protected];[email protected];lily.O'[email protected]) will cause error. How can I get the result [email protected];[email protected];lily.O'[email protected] by using %str or any other macro quote function like %bquote or anything else to keep that single quote unmatched?

THE EMAIL LIST IS imported from excel list and I already put% before the single quote in the excel file: lily.O%'[email protected] and HOW can I get the the macro variable &email. value inside the %str(), namely: [email protected];[email protected];lily.O%'[email protected] then I can put macro variable into %str()?

2

2 Answers

1
votes

If you have the value already in a macro variable, say from a data step via CALL SYMPUTX() function call or from PROC SQL via INTO clause, then you can use %SUPERQ() macro function to macro quote the value.

data _null_;
  call symputx('unquoted',"O'[email protected]");
run;
%put Email list = %superq(unquoted);

If the value is already in a macro variable the the %BQUOTE() function would also work.

%put Email list = %bquote(&unquoted);

You could even use the RESOLVE() function to call %SUPERQ() to get the macro variable redefined with macro quoting immediately after creating it. So if you have a dataset MYTABLE with a variable EMAIL_LIST you could generate a series of separate macro variables (list1,list2, etc) from the data using code like this.

data _null_;
  set mytable ;
  length mvar rc $32 ;
  mvar = cats('list',_n_);
  call symputx(mvar,email_list);
  rc = resolve(catx(' ','%let',mvar,'=%superq(',mvar,');'));
run;

The first example data step works since the string literal used double quotes on the outside and thus protected the unbalanced single quote. You could do the same thing in macro code by using the %QSYSFUNC() macro function to call the DEQUOTE() function. Note that you would have trouble if the value includes double quote characters. They would need to be converted to two adjacent double quotes.

 %put Email list = %qsysfunc(dequote("O'[email protected]"));
0
votes

With %STR, you need to mark unmatched quotes with a % sign. So try:

%STR([email protected];[email protected];lily.O%'[email protected])