<?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: issues parasing a single quote in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901886#M356395</link>
    <description>&lt;P&gt;What exactly are you having trouble with?&lt;/P&gt;
&lt;P&gt;I am not sure how a database comes into this problem.&amp;nbsp; You appear to be just showing data step code to write part of an HTML file.&amp;nbsp; And it does not even reference any dataset variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do have in the macro variable ESCAPEDVALUE?&lt;/P&gt;
&lt;P&gt;What do you want written to the HTML file?&lt;/P&gt;</description>
    <pubDate>Tue, 07 Nov 2023 14:18:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-11-07T14:18:53Z</dc:date>
    <item>
      <title>issues parasing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901882#M356394</link>
      <description>&lt;P&gt;Hello. I came here a few weeks ago because I was working on a solution where I was generating HTML to update some tables in SAS.&amp;nbsp; Thanks to the sas community, I am 99% complete. I have one use case that refuses to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;put " &amp;lt;INPUT TYPE='Text' NAME='CompanyName' width='50' value=""" "&amp;amp;EscapedValue.""" maxlength='100'&amp;gt;&amp;lt;br&amp;gt;";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the one use case that fails, the value returned from the database contains a single quote.&amp;nbsp; &amp;nbsp;I have tried everything I can to escape it. I can't replace with an ascii equivalent because I use that value to join to another table and it needs to match the value there.&amp;nbsp; Any suggestions would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901882#M356394</guid>
      <dc:creator>RustyOwens</dc:creator>
      <dc:date>2023-11-07T14:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: issues parasing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901886#M356395</link>
      <description>&lt;P&gt;What exactly are you having trouble with?&lt;/P&gt;
&lt;P&gt;I am not sure how a database comes into this problem.&amp;nbsp; You appear to be just showing data step code to write part of an HTML file.&amp;nbsp; And it does not even reference any dataset variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do have in the macro variable ESCAPEDVALUE?&lt;/P&gt;
&lt;P&gt;What do you want written to the HTML file?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901886#M356395</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-07T14:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: issues parsing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901887#M356396</link>
      <description>&lt;P&gt;My apologies.&amp;nbsp; Here is the is the full code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc printto new log='/sas/config/Lev1/SASApp/SASEnvironment/SASCode/Edit_Company.log';&lt;BR /&gt;libname National '/vol2/mars/national';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* %macro extract_id(value);&lt;BR /&gt;%let id = %scan(&amp;amp;value, -1, _);&lt;BR /&gt;%put The extracted id is: &amp;amp;id;&lt;BR /&gt;%mend extract_id; */&lt;/P&gt;&lt;P&gt;/* Example usage */&lt;BR /&gt;/* * %extract_id(AAP_REQUEST_123); */&lt;/P&gt;&lt;P&gt;/* Utilize the parameter */&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select Companyname into :CompanyName&lt;BR /&gt;from National.Company&lt;BR /&gt;where id = &amp;amp;id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%let EscapedCompanyName = %sysfunc(tranwrd(%sysfunc(dequote("&amp;amp;CompanyName.")), "'", "''"));&lt;/P&gt;&lt;P&gt;/* Assign the value of the escaped Companyname to a new variable */&lt;BR /&gt;%let EscapedCompanyName = %sysfunc(tranwrd(%sysfunc(dequote("&amp;amp;CompanyName.")), "'", "''"));&lt;/P&gt;&lt;P&gt;/* Assign the value of the escaped Companyname to a new variable */&lt;BR /&gt;%let EscapedValue = &amp;amp;EscapedCompanyName;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;file _webout;&lt;/P&gt;&lt;P&gt;put '&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "&lt;A href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&lt;/A&gt;"&amp;gt;';&lt;BR /&gt;put '&amp;lt;html&amp;gt;';&lt;BR /&gt;put '&amp;lt;head&amp;gt;';&lt;BR /&gt;put '&amp;lt;title&amp;gt;National Accounts Oneline Program&amp;lt;/title&amp;gt; ';&lt;BR /&gt;put '&amp;lt;meta name="Author" content="Crystal"&amp;gt;';&lt;BR /&gt;put '&amp;lt;meta name="Description" content="National Accounts Oneline Program"&amp;gt;';&lt;BR /&gt;put '&amp;lt;link rel="stylesheet" type="text/css" href="S:\Workgroups\SC Marketing\SCS Marketing Services\System Support (soco Read Only Access)\Load Research\LR ART\main_style.css"&amp;gt;';&lt;BR /&gt;put '&amp;lt;/head&amp;gt;';&lt;BR /&gt;put '&amp;lt;body&amp;gt;';&lt;BR /&gt;put '&amp;lt;div id="container_fullmain"&amp;gt;';&lt;BR /&gt;put ' &amp;lt;div id="header" align=center&amp;gt;&amp;lt;strong&amp;gt;Edit Company&amp;lt;/strong&amp;gt;&amp;lt;/div&amp;gt;';&lt;BR /&gt;put ' ';&lt;BR /&gt;put '&amp;lt;div align=Center&amp;gt;';&lt;BR /&gt;put " &amp;lt;a href='https://&amp;amp;trimmed_url./SASStoredProcess/do?_PROGRAM=/Stored_Processes/csg/Oneline_home'&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;";&lt;BR /&gt;put '&amp;lt;/div&amp;gt;';&lt;BR /&gt;put ' &amp;lt;div id="container_wide"&amp;gt;';&lt;BR /&gt;put ' &amp;lt;form name="oneline" method=put ACTION="/SASStoredProcess/do"&amp;gt;' ;&lt;BR /&gt;put '&amp;lt;table&amp;gt;';&lt;BR /&gt;put ' &amp;lt;tr&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;th&amp;gt;Name of company:&amp;lt;/th&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;td&amp;gt; ';&lt;BR /&gt;put " &amp;lt;INPUT TYPE='Text' NAME='CompanyName' width='50' value=""" "&amp;amp;EscapedValue.""" maxlength='100'&amp;gt;&amp;lt;br&amp;gt;";&lt;BR /&gt;put " &amp;lt;INPUT TYPE='hidden' NAME='id' width= '50' value=""&amp;amp;id"" maxlength='100'&amp;gt;&amp;lt;br&amp;gt;";&lt;BR /&gt;put ' &amp;lt;/td&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;/tr&amp;gt;';&lt;BR /&gt;put ' &amp;lt;tr&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;td&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;input type="hidden" name="_program" value="/Stored_Processes/csg/Edit_Company_Action"&amp;gt;';&lt;BR /&gt;put ' &amp;lt;input type="submit" value="Edit Company" class="goButton_long"&amp;gt;';&lt;BR /&gt;put ' &amp;lt;/td&amp;gt; ';&lt;BR /&gt;put ' &amp;lt;/tr&amp;gt;';&lt;BR /&gt;put ' ' ;&lt;BR /&gt;put ' ' ;&lt;BR /&gt;put ' &amp;lt;br&amp;gt;';&lt;BR /&gt;put ' &amp;lt;center&amp;gt;&amp;lt;/center&amp;gt;';&lt;BR /&gt;put ' &amp;lt;/FORM&amp;gt;';&lt;BR /&gt;put ' &amp;lt;/div&amp;gt;';&lt;BR /&gt;put ' &amp;lt;/div&amp;gt;';&lt;BR /&gt;put '&amp;lt;/div&amp;gt; ';&lt;BR /&gt;put '&amp;lt;/body&amp;gt; ';&lt;BR /&gt;put '&amp;lt;/html&amp;gt; ';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901887#M356396</guid>
      <dc:creator>RustyOwens</dc:creator>
      <dc:date>2023-11-07T14:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: issues parsing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901891#M356397</link>
      <description>&lt;P&gt;Why mess around with the strings as macro variables if you are going to run a DATA step anyway.&lt;/P&gt;
&lt;P&gt;You seem to be writing values inside of single quotes for the other HTML tags.&amp;nbsp; So use QUOTE() to quote your CompanyName with single quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set National.Company;
  where id = &amp;amp;id;
  file _webout;
...
  length quoted_name $300;
  quoted_name = quote(trim(CompanyName),"'");
put " &amp;lt;INPUT TYPE='Text' NAME='CompanyName' width='50' value=" 
   quoted_name " maxlength='100'&amp;gt;&amp;lt;br&amp;gt;";
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if companyname is "Bob's Burgers" then that should write:&lt;/P&gt;
&lt;PRE&gt;value='Bob''s Burgers'&lt;/PRE&gt;
&lt;P&gt;into the HTML file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that does not work for HTML then try something else.&amp;nbsp; Perhaps using HTMLENCODE() so perhaps you write it as:&lt;/P&gt;
&lt;PRE&gt;value='Bob&amp;amp;amp;s Burgers'&lt;/PRE&gt;
&lt;P&gt;Instead.&amp;nbsp; That might work better as a web form.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901891#M356397</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-07T14:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: issues parsing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901892#M356398</link>
      <description>&lt;P&gt;Forgive my inexperience and lack of experience in SAS. What I want is if the company name in the query is Bob's Burgers then I need Bob's Burgers to populate in the textbox. Will this do that?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901892#M356398</guid>
      <dc:creator>RustyOwens</dc:creator>
      <dc:date>2023-11-07T14:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: issues parsing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901902#M356402</link>
      <description>&lt;P&gt;HTML files are TEXT files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So try making an example one yourself and then edit it with a text editor and see what combinations of characters work.&amp;nbsp; I would try each of these version (leave the rest of the HTML file unchanged).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value="Bob's Burger"
value='Bob''s Burger'
value='Bob&lt;SPAN&gt;&amp;amp;apos&lt;/SPAN&gt;;s Burger'
value="Bob&lt;SPAN&gt;&amp;amp;apos;&lt;/SPAN&gt;s Burger"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So those are in order.&amp;nbsp; quoted with double quotes.&amp;nbsp; quoted with single quotes with embedded single quotes doubled.&amp;nbsp; Single quote replaced by HTML command for an apostrophe and quoted with single quotes.&amp;nbsp; Same but quoted by double quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you know which string works for HTML then you can work on how to get SAS to generate that string.&lt;/P&gt;
&lt;P&gt;Again in order you can make those strings like this :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  quoted_company1=quote(trim(company_name));
  quoted_company2=quote(trim(company_name),"'");
  quoted_company3=quote(tranwrd(trim(company_name),"'",'&amp;amp;apos;'),"'");
  quoted_company4=quote(tranwrd(trim(company_name),"'",'&amp;amp;apos;'));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's try it out.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename test 'c:\downloads\apos_test.html';
data test;
  file test;
  put '&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;pre&amp;gt;';
  company_name="Bob's Burgers";
  length quoted_company1 - quoted_company4 $50;
  quoted_company1=quote(trim(company_name));
  quoted_company2=quote(trim(company_name),"'");
  quoted_company3=quote(tranwrd(trim(company_name),"'",'&amp;amp;apos;'),"'");
  quoted_company4=quote(tranwrd(trim(company_name),"'",'&amp;amp;apos;'));
  put (quoted:) (=/);
  put '&amp;lt;/pre&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1699371529267.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89488iB07BC1C0CFD326B3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1699371529267.png" alt="Tom_0-1699371529267.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So at least for just printing the text into a normal HTML file all but the second method works fine.&lt;/P&gt;
&lt;P&gt;If you know the values have single quotes in them but do not have double qutoes then just use the first method.&amp;nbsp; That is easy to produce in a data step since you can use the $QUOTE format to print the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put ..... 'value=' company_name :$quote. .... ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values might have double quote characters in them then I would use the third method since the resulting string as single quotes around it so that if you accidentally use it in a place where the SAS macro processor will look at it then the &amp;amp;apos; HTML command will not be mistaken for a reference to a macro variable named APOS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 15:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901902#M356402</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-07T15:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: issues parsing a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901989#M356418</link>
      <description>&lt;P&gt;SAS function &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0cm3nfzxlg3iwn1myjzv3t8rt8j.htm" target="_self"&gt;htmlencode()&lt;/A&gt; lets you encode such characters.&lt;/P&gt;
&lt;P&gt;Below how this could work for single and double quotes and the ampersand with minimal change to your existing code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  Companyname="Bob's Burger";
run;

proc sql noprint;
  select htmlencode(Companyname,'apos quot amp') into :CompanyName
  from work.have
  /*where id = &amp;amp;id*/
  ;
quit;

%put CompanyName: %nrbquote(&amp;amp;CompanyName);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1699397079350.png" style="width: 609px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89517iF1BBA27FB20E3180/image-dimensions/609x54?v=v2" width="609" height="54" role="button" title="Patrick_0-1699397079350.png" alt="Patrick_0-1699397079350.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 22:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issues-parasing-a-single-quote/m-p/901989#M356418</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-07T22:48:09Z</dc:date>
    </item>
  </channel>
</rss>

