- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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;