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?
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;
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;
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.
%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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.