DATA Step, Macro, Functions and more

Concatenate Single Quote with text of a Macro Variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

Concatenate Single Quote with text of a Macro Variable

Hi,

I have a macro variable dep_var as

[pre] %let dep_var=yld syld myld; [/pre]
I want a new macro variable as say
[pre]new_dep='yld syld myld' [/pre]
i.e I want to cocatenate the text of my macro variable dep_var with single quotes.

Thanks.

Accepted Solutions
Solution
‎08-14-2017 02:55 PM
SAS Employee
Posts: 7

Re: Concatenate Single Quote with text of a Macro Variable

Posted in reply to MKhandelwal

There are 2 ways to accomplish this task.

 

%let dep_var=yld syld myld;

 

Method 1:

%let new_var2=%unquote(%str(%'&dep_var%'));

 

Method 2 (If running SAS 9.4 or greater):

%let new_var3=%tslit(&dep_var);

 

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: Concatenate Single Quote with text of a Macro Variable

Posted in reply to MKhandelwal
%str(%') is needed. You may need to unquote the value, now or later.

[pre]
927 %let dep_var=yld syld myld;
928 %let new_var1=%str(%')&dep_var.%str(%');
929 %let new_var2=%unquote(%str(%')&dep_var.%str(%'));
930
931 %put _user_;
GLOBAL NEW_VAR2 'yld syld myld'
GLOBAL NEW_VAR1 yld syld myld
GLOBAL DEP_VAR yld syld myld
[/pre]
Solution
‎08-14-2017 02:55 PM
SAS Employee
Posts: 7

Re: Concatenate Single Quote with text of a Macro Variable

Posted in reply to MKhandelwal

There are 2 ways to accomplish this task.

 

%let dep_var=yld syld myld;

 

Method 1:

%let new_var2=%unquote(%str(%'&dep_var%'));

 

Method 2 (If running SAS 9.4 or greater):

%let new_var3=%tslit(&dep_var);

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 9124 views
  • 1 like
  • 3 in conversation