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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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