<?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: What quoting function to use? Tried everything and not getting result expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912898#M359831</link>
    <description>&lt;P&gt;Likely overthinking things a bit. There are other search functions besides LIKE that can completely avoid the use of any macro triggers you get from the %&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this is what you want:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.lines as 
   select t1.*
      from work.logStream t1
    where index(upcase(strline),"&amp;amp;webService")&amp;gt;0 and 
          index( upcase(strline),"HTTPS")=0 
      ;    
quit;&lt;/PRE&gt;
&lt;P&gt;The index function return the position in a string of the second parameter in the first. So index=0 is "not found".&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2024 21:04:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-01-24T21:04:52Z</dc:date>
    <item>
      <title>What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912897#M359830</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data logStream;
   strId=1;strline="xxxxMyJob XX XXX X bbbbbbb aaaaaaa cccccccc";output;
   strId=2;strline="https//:xxxx aaaMYJOB XX XXX X";output;
   strId=3;strline="xxxx jobstorun XX XXX X";output;
   strId=4;strline="xxxx jobstorun myjobXX XXX Xrp";output;
   strId=5;strline="https//:xxxx yuiuyhiuo XX XXX X";output;
run;

%let webService=%upcase(myJob);

/* Love the LIKE functionality with wildcard "%" ===&amp;gt; "%string%" */

/*However I would like to remove the hardcoding MYJOB to be replaced by the macro variable &amp;lt;webService&amp;gt;.
I have tried all the quoting functions(%str, %nrstr,%unquote,%bquote, %quote, %nrquote, etc..." unsucessfully. Definitively I don't understand them.
Please help and correct the commented line below.*/

proc sql;
   create table work.lines as 
   select t1.*
      from work.logStream t1
      where upcase(strline) like "%MYJOB%" and NOT upcase(strline) like upcase("%https%")       /*works */
/*    where upcase(strline) like "%&amp;amp;webService%" and NOT upcase(strline) like upcase("%https%") */   /* help */
      ;    
quit;

/* Result expected: row  1 and 4 */
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2024 20:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912897#M359830</guid>
      <dc:creator>PopCorn14</dc:creator>
      <dc:date>2024-01-24T20:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912898#M359831</link>
      <description>&lt;P&gt;Likely overthinking things a bit. There are other search functions besides LIKE that can completely avoid the use of any macro triggers you get from the %&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this is what you want:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.lines as 
   select t1.*
      from work.logStream t1
    where index(upcase(strline),"&amp;amp;webService")&amp;gt;0 and 
          index( upcase(strline),"HTTPS")=0 
      ;    
quit;&lt;/PRE&gt;
&lt;P&gt;The index function return the position in a string of the second parameter in the first. So index=0 is "not found".&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 21:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912898#M359831</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-24T21:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912900#M359832</link>
      <description>&lt;P&gt;%NRSTR() works pretty well.&amp;nbsp; Double up the %'s in the string.&lt;/P&gt;
&lt;P&gt;%BQUOTE() also helps since you can then add single quotes around the value.&lt;/P&gt;
&lt;PRE&gt;1    %let x=%bquote('%nrstr(%%)abc');
2    %put &amp;amp;x;
'%abc'
&lt;/PRE&gt;
&lt;P&gt;For your particular use case just don't use LIKE.&amp;nbsp; CONTAINS will test for a substring.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where upcase(strline) contains %upcase("&amp;amp;webService")
   and NOT (upcase(strline) contains 'HTTPS')
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 21:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912900#M359832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-24T21:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912914#M359840</link>
      <description>&lt;P&gt;Below two options when using the like operator&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data logStream;
  infile datalines truncover dlm='|';
  input strID strline:$60.;
  datalines;
1|xxxxMyJob XX XXX X bbbbbbb aaaaaaa cccccccc
2|https//:xxxx aaaMYJOB XX XXX X
3|xxxx jobstorun XX XXX X
4|xxxx jobstorun myjobXX XXX Xrp
5|https//:xxxx yuiuyhiuo XX XXX X
;

/* option 1 */
%let mvar=myJob;

proc sql;
/*  create table work.lines as */
  select t1.*
  from work.logStream t1
  where upcase(strline) like cats('%',upcase("&amp;amp;mvar"),'%')
  ;    
quit;

/* option 2 */
%let mvar=myJob;
data _null_;
  call symputx('mvar',cats('%',"&amp;amp;mvar",'%'));
run;

proc sql;
/*  create table work.lines as */
  select t1.*
  from work.logStream t1
  where upcase(strline) like upcase(symget("mvar"))
  ;    
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2024 01:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/912914#M359840</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-25T01:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/913007#M359875</link>
      <description>&lt;P&gt;Thank you all &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;. All solutions were great.&lt;BR /&gt;I learned different ways!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had to select one "Accepted solution" and couldn't decided....all so nicely written.&lt;/P&gt;
&lt;P&gt;However since&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; had provided an example with %bquote and %nrstr, I chose that solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Everything I tried with bquote, I didn't understand how to use it.&lt;/P&gt;
&lt;P&gt;One of my bad attempts example&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&lt;BR /&gt;where upcase(strline) like "%bquote(%&amp;amp;webService%)" ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But thank you very much.&amp;nbsp; Very helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 17:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/913007#M359875</guid>
      <dc:creator>PopCorn14</dc:creator>
      <dc:date>2024-01-25T17:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/913010#M359877</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.  &lt;BR /&gt;Love the index function.</description>
      <pubDate>Thu, 25 Jan 2024 17:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/913010#M359877</guid>
      <dc:creator>PopCorn14</dc:creator>
      <dc:date>2024-01-25T17:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: What quoting function to use? Tried everything and not getting result expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/913013#M359879</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; for showing 2 options.  I like the fact that you gave me an opportunity to still use the LIKE by using the CATS for the "%"  which I was really wanted to use.  Also learned how to use the symget.  Cool.</description>
      <pubDate>Thu, 25 Jan 2024 17:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-quoting-function-to-use-Tried-everything-and-not-getting/m-p/913013#M359879</guid>
      <dc:creator>PopCorn14</dc:creator>
      <dc:date>2024-01-25T17:27:13Z</dc:date>
    </item>
  </channel>
</rss>

