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