BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sburnos
Fluorite | Level 6

Dear SAS community,

 

Struggling with an issue to add a single quote symbol into a macro var by function twanwrd and add it to a label of a variable.

The idea, that I want to have a label of a var as "Smith' car". At the moment I have a macro var "SmithZZZ car".

This is the code I am using:

 

%let have=SmithZZZ car;

 

data temp;
   var1="have";
   var2="want";
   label var1="&have";

   %let want=%sysfunc(tranwrd(%bquote(&have),%str(ZZZ),%str(%')));
   label var2="&want";

run;

 

this code does not work,  and I tried many ways to solve the issue, but without success. 

Could anyone propose a solution?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So, I can't see any purpose for your data step. The following ought to work:

 

%let have=SmithZZZ car;
%put &=have;

%let want=%qsysfunc(tranwrd(&have,ZZZ,%str(%')));
%put &=want;

or even simpler, without macro variables

 

data a;
    have='SmithZZZ car';
    want=tranwrd(have,'ZZZ',"'");
run;

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

So, I can't see any purpose for your data step. The following ought to work:

 

%let have=SmithZZZ car;
%put &=have;

%let want=%qsysfunc(tranwrd(&have,ZZZ,%str(%')));
%put &=want;

or even simpler, without macro variables

 

data a;
    have='SmithZZZ car';
    want=tranwrd(have,'ZZZ',"'");
run;

 

--
Paige Miller
sburnos
Fluorite | Level 6

Thank you a lot. Have spent a day on searching for a solution. You replied within 10 minutes.

For the future will use the help of SAS community more frequently.

 

Regarding data step, my ultimate goal was to assign the value of macro variable to a label. Therefore I needed that.

 

Ksharp
Super User
%let have=SmithZZZ car;
%let want=%bquote(%sysfunc(prxchange(s/Z+\b/%str(%')/i,1,&have)));

%put &have;
%put &want;

title "&want";
proc print data=sashelp.class;run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1822 views
  • 3 likes
  • 3 in conversation