Dear,
I am trying create a variable having quoted words. Please suggest. Thank you
In the macro one, the item variable is not created. Please suggest. Thank you
data one;
input want $;
datalines;
aaaaaaa
;
run;
%macro one;
data two;
length item $200.;
set one;
item = %str("Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.") ;
run;
%mend;
%one;
In DATA TWO, you have
item = %str("Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.") ;
But ITEM is a data set variable, not a macro variable. %STR() shgouldn't be used to create data set variables. Just create ITEM using whatever text strings you want using proper DATA step syntax for creating character strings.
In fact, your macros are meaningless in this code, they add no value. Get the code to work without macros and without macro variables.
Try either:
item = %str('Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.') ;
/* replace open&close from double quotes to single quotes */
or
item = %str("Med terms ""Neoplasm progression"", ""Malignant progression"" and ""Disease progression"" drug are excluded.") ;
/* double each internal double quote ot replace it to single quotes *.
item = %str("Med terms 'Neoplasm progression', 'Malignant progression' and 'Disease progression' drug are excluded.") ;
What value does using %STR() add?
How about this:
item='Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.';
I don't see where you are planning to use macro variables.
Your code is attempting to define the variable ITEM in the dataset TWO, but it is using the wrong syntax for specifying a string that includes quotes.
Either use a different character on the outside.
'Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.'
"Med terms 'Neoplasm progression', 'Malignant progression' and 'Disease progression' drug are excluded."
Or double any embedded quotes.
"Med terms ""Neoplasm progression"", ""Malignant progression"" and ""Disease progression"" drug are excluded."
If you actually had a macro variable.
%let terms=Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.;
And you wanted to use it to generate your string use the QUOTE() function.
items=%sysfunc(quote(&terms));
If the macro variable has unbalanced quotes then add macro quoting to it. Or add it before passing the value to QUOTE().
items=%sysfunc(quote(%superq(terms)));
You don't need a macro definition, and you don't need the %STR function..
Solve your issue by using single quotes around your string, as already proposed.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: