<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with functions of masking quotes. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226052#M40649</link>
    <description>&lt;P&gt;To me it looks like you are trying to add beginning and ending % wildcard characters to the value of macro variable to use in the SQL LIKE clause. &amp;nbsp;It is much easier if you just use double quotes and * in place of single quotes and % and then convert them later using something like the TRANSLATE() function. &amp;nbsp;Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mvar=fr ;
%let like_value=%sysfunc(translate("*&amp;amp;mvar*",'%',"*"));
%Put &amp;amp;=like_value;
proc sql ;
   select * from sashelp.class where name like &amp;amp;like_value ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Sep 2015 14:34:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2015-09-17T14:34:05Z</dc:date>
    <item>
      <title>Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226008#M40628</link>
      <description>&lt;P&gt;I have a problem with the macro variables using the functions of masking quotes. In the first example, using 'call symput' macro variable 'x' is created and printed correctly, but then at run a proc sql, the use of this macro variable creates an error.&lt;/P&gt;
&lt;P&gt;In the second example they are made to the same things, with the addition of call symput to create the macro again variable, then the execution of proc sql does not create errors.&lt;/P&gt;
&lt;P&gt;I do not understand why it was necessary to call symput, when printing the macro variable before gave a correct result. I do not understand why the first example it faults.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*** datasets starting ***/&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;length note $ 10.;&lt;/P&gt;
&lt;P&gt;note = "test1";output;&lt;/P&gt;
&lt;P&gt;note = "test2";output;&lt;/P&gt;
&lt;P&gt;note = "test3";output;&lt;/P&gt;
&lt;P&gt;note = "no_present1";output;&lt;/P&gt;
&lt;P&gt;note = "no_present2";output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*** first example:*/&lt;/P&gt;
&lt;P&gt;%let testo1 =&amp;nbsp; test;&lt;/P&gt;
&lt;P&gt;%let x = %nrstr(%')%str(%%)%cmpres(&amp;amp;testo1)%str(%%%');&lt;/P&gt;
&lt;P&gt;OPTIONS MPRINT;&lt;/P&gt;
&lt;P&gt;%macro ex_1();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sel2 as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from test&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where note like &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;ex_1&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*** second example ***/&lt;/P&gt;
&lt;P&gt;%let testo1 =&amp;nbsp; test;&lt;/P&gt;
&lt;P&gt;%let x = %nrstr(%')%str(%%)%cmpres(&amp;amp;testo1)%str(%%%');&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;x="&amp;amp;x";&lt;/P&gt;
&lt;P&gt;call symput ('x',x);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;OPTIONS MPRINT;&lt;/P&gt;
&lt;P&gt;%macro ex_2();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sel2 as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from test&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where note like &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;ex_2;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 09:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226008#M40628</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2015-09-17T09:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226011#M40631</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to say, my opinion is that as soon as there is more than one % in a line of code, then there is a strong possiblity of doing things another way and in simple syntax. &amp;nbsp;E.g.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let testo1 =&amp;nbsp; test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; call execute("&lt;/SPAN&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create table sel2 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from test&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where note like '"||strip(&amp;amp;x)||"';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;quit;");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are plenty of other ways of coding these things, why do you need to go through all that&amp;nbsp;&lt;SPAN&gt;%nrstr(%')%str(%%)%cmpres(&amp;amp;testo1)%str(%%%');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;just to use macro facility? &amp;nbsp;If you supply the problem, maybe other solutions can be provided.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 10:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226011#M40631</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-09-17T10:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226032#M40640</link>
      <description>&lt;P&gt;You need to unquote your value. You can avoid the call symput like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*** first example:*/&lt;/P&gt;&lt;P&gt;%let testo1 = test;&lt;/P&gt;&lt;P&gt;%let x = %unquote(%nrstr(%'%%)&amp;amp;testo1%str(%%%'));&lt;/P&gt;&lt;P&gt;OPTIONS MPRINT;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; ex_1();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sel2 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where note like &amp;amp;x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;ex_1&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 12:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226032#M40640</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-09-17T12:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226034#M40642</link>
      <description>&lt;P&gt;Boy I really dislike the new forum layout!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not much fits on the screen anymore as it is very sparse, the banner at the top wastes even more space. It is ridiculously wide. The top half of the screen is polluted before we can see any content.&lt;/P&gt;&lt;P&gt;And now I see that the tedious paste to MS word to keep the code font/colors no longer works.&lt;/P&gt;&lt;P&gt;So much for progress!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 12:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226034#M40642</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-09-17T12:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226052#M40649</link>
      <description>&lt;P&gt;To me it looks like you are trying to add beginning and ending % wildcard characters to the value of macro variable to use in the SQL LIKE clause. &amp;nbsp;It is much easier if you just use double quotes and * in place of single quotes and % and then convert them later using something like the TRANSLATE() function. &amp;nbsp;Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mvar=fr ;
%let like_value=%sysfunc(translate("*&amp;amp;mvar*",'%',"*"));
%Put &amp;amp;=like_value;
proc sql ;
   select * from sashelp.class where name like &amp;amp;like_value ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 14:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226052#M40649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-17T14:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226059#M40650</link>
      <description>&lt;P&gt;Thanks RW9.&lt;/P&gt;
&lt;P&gt;I need to go through all that nrstr% (% ')% str (%%)% cmpres (and text1)% str (%%%')&lt;BR /&gt;because I need to write a variable text between the characters '% and&amp;nbsp;%' to use like in proc sql.&lt;/P&gt;
&lt;P&gt;Do you know other ways?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 14:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226059#M40650</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2015-09-17T14:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226156#M40674</link>
      <description>&lt;P&gt;It's generally easier to get these complex strings into a macro variable using a DATA step.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let test01 = test;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput('x', ' ''%' || "&amp;amp;test01" || '%'' ');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you should be able to refer to &amp;amp;x in the SQL code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 22:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226156#M40674</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-09-17T22:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with functions of masking quotes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226273#M40722</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961" target="_self"&gt;Chris_NewZealan&lt;WBR /&gt;d&lt;/A&gt;!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 13:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-functions-of-masking-quotes/m-p/226273#M40722</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2015-09-18T13:49:34Z</dc:date>
    </item>
  </channel>
</rss>

