Help using Base SAS procedures

Tranwrd function

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

Tranwrd function

Hi Experts,

this is have:

%let string=i need apostrophe instead of question mark?ed

want:

i need apostrophe instead of question mark'ed

i am using below

data t;

var="&string";

var1=tranwrd(trim(var),"?",",");

call symput("want",var1);

run;

%put &want;

i am getting error :Literal contains unmatched quote.

Thanks

Sam


Accepted Solutions
Solution
‎03-18-2015 04:58 PM
Respected Advisor
Posts: 3,777

Re: Tranwrd function

If you are successful you will create a macro variable with and un-quoted single quote.  This will need special attention depending on what you do next.

It is probably better to quote the unmatched single quote with %str((%');

32         %let string=i need apostrophe instead of question mark%str(%')ed;
33         %put NOTE: &=string;
NOTE: STRING=i need apostrophe instead of question mark'ed

%let string=i need apostrophe instead of question mark?ed;

data _null_;
   var=
"&string";
   var1=transtrn(trim(var),
"?","'");
   call symput("want",var1);
   run;

%put %bquote(&want);


32        
%let string=i need apostrophe instead of question mark?ed;
35         data _null_;
36            var="&string";
37            var1=transtrn(trim(var),"?","'");
38            call symput("want",var1);
39            run;
40        
41        
%put %bquote(&want);
i need apostrophe instead of question mark'ed                                                                                      
                                                  

View solution in original post


All Replies
Super Contributor
Posts: 490

Re: Tranwrd function

Your code should work.

Please post the complete log

Solution
‎03-18-2015 04:58 PM
Respected Advisor
Posts: 3,777

Re: Tranwrd function

If you are successful you will create a macro variable with and un-quoted single quote.  This will need special attention depending on what you do next.

It is probably better to quote the unmatched single quote with %str((%');

32         %let string=i need apostrophe instead of question mark%str(%')ed;
33         %put NOTE: &=string;
NOTE: STRING=i need apostrophe instead of question mark'ed

%let string=i need apostrophe instead of question mark?ed;

data _null_;
   var=
"&string";
   var1=transtrn(trim(var),
"?","'");
   call symput("want",var1);
   run;

%put %bquote(&want);


32        
%let string=i need apostrophe instead of question mark?ed;
35         data _null_;
36            var="&string";
37            var1=transtrn(trim(var),"?","'");
38            call symput("want",var1);
39            run;
40        
41        
%put %bquote(&want);
i need apostrophe instead of question mark'ed                                                                                      
                                                  
Regular Contributor
Posts: 168

Re: Tranwrd function

Thank you data _null_. I was not successful at first macro variable itself. so i am getting issue.

Thanks

Sam

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 283 views
  • 0 likes
  • 3 in conversation