BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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;
5 REPLIES 5
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Shmuel
Garnet | Level 18

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.") ;
PaigeMiller
Diamond | Level 26

What value does using %STR() add?

 

How about this:

item='Med terms "Neoplasm progression", "Malignant progression" and "Disease progression" drug are excluded.';
--
Paige Miller
Tom
Super User Tom
Super User

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)));

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1050 views
  • 5 likes
  • 5 in conversation