<?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 PROC SQL.. .How to insert the following XML as string? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874674#M38818</link>
    <description>&lt;P&gt;I want to insert the XML as a string. May refer to the SAS code.&lt;/P&gt;&lt;P&gt;Not sure if there are double quote within the string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;&lt;BR /&gt;    create table A (Requested_XML varchar(3000));&lt;BR /&gt;&lt;BR /&gt;proc sql;
	insert into A values
"&amp;lt;?xml version="1.0"?&amp;gt;&amp;lt;catalog&amp;gt;   &amp;lt;book id="bk101"&amp;gt;      &amp;lt;author&amp;gt;Gambardella, Matthew&amp;lt;/author&amp;gt;      &amp;lt;title&amp;gt;XML Developer's Guide&amp;lt;/title&amp;gt;      &amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;      &amp;lt;price&amp;gt;44.95&amp;lt;/price&amp;gt;      &amp;lt;publish_date&amp;gt;2000-10-01&amp;lt;/publish_date&amp;gt;      &amp;lt;description&amp;gt;An in-depth look at creating applications  with XML.&amp;lt;/description&amp;gt;   &amp;lt;/book&amp;gt;";&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,a datetime constant,a missing value, ), +, ',', -, MISSING, NULL, USER.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR 79-322: Expecting a (.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;ERROR: Bit Constants are not supported by SQL.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2023 15:16:53 GMT</pubDate>
    <dc:creator>ChrisWoo</dc:creator>
    <dc:date>2023-05-09T15:16:53Z</dc:date>
    <item>
      <title>PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874674#M38818</link>
      <description>&lt;P&gt;I want to insert the XML as a string. May refer to the SAS code.&lt;/P&gt;&lt;P&gt;Not sure if there are double quote within the string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;&lt;BR /&gt;    create table A (Requested_XML varchar(3000));&lt;BR /&gt;&lt;BR /&gt;proc sql;
	insert into A values
"&amp;lt;?xml version="1.0"?&amp;gt;&amp;lt;catalog&amp;gt;   &amp;lt;book id="bk101"&amp;gt;      &amp;lt;author&amp;gt;Gambardella, Matthew&amp;lt;/author&amp;gt;      &amp;lt;title&amp;gt;XML Developer's Guide&amp;lt;/title&amp;gt;      &amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;      &amp;lt;price&amp;gt;44.95&amp;lt;/price&amp;gt;      &amp;lt;publish_date&amp;gt;2000-10-01&amp;lt;/publish_date&amp;gt;      &amp;lt;description&amp;gt;An in-depth look at creating applications  with XML.&amp;lt;/description&amp;gt;   &amp;lt;/book&amp;gt;";&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,a datetime constant,a missing value, ), +, ',', -, MISSING, NULL, USER.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR 79-322: Expecting a (.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;ERROR: Bit Constants are not supported by SQL.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874674#M38818</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-09T15:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874675#M38819</link>
      <description>&lt;P&gt;To make a string literal in SAS you can use " or ' on the outside.&amp;nbsp; But if the character you want to use on the outside exists in the data you need to double it up.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you string looks like:&lt;/P&gt;
&lt;PRE&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;/PRE&gt;
&lt;P&gt;And you want to enclose it in " then you need to change it to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;lt;?xml version=""1.0""?&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Before adding the quotes.&lt;/P&gt;
&lt;PRE&gt;"&amp;lt;?xml version=""1.0""?&amp;gt;"&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2023 15:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874675#M38819</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-09T15:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874676#M38820</link>
      <description>&lt;P&gt;If you need to have double quotes in a string, use single quotes "on the outside".&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874676#M38820</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-09T15:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874677#M38821</link>
      <description>i see.. TQVM</description>
      <pubDate>Tue, 09 May 2023 15:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874677#M38821</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-09T15:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874678#M38822</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any other way that I can do it without putting additional single / double quotes on every strings that contain quotes like "Chris"?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874678#M38822</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-09T15:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874679#M38823</link>
      <description>&lt;P&gt;Copy from the LOG the entire procedure with code and the error messages. On the forum open a text box and paste the entire log.&lt;/P&gt;
&lt;P&gt;Typically the 22-322 error, and many others will place diagnostic characters into the log where the problem occurs so it helps to see that. Also the main message windows will reformat pasted text meaning that those diagnostic characters appear incorrectly if not pasted into a text box that preserves text format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One strongly suspects it is related to multiple quotes, both single and double.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;"&lt;/STRONG&gt;&lt;/FONT&gt;&amp;lt;?xml version=&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;"&lt;/STRONG&gt;&lt;/FONT&gt;1.0"?&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second magenta " above would end the "value" treated as &amp;lt;?xml version=1&lt;/P&gt;
&lt;P&gt;the 1. would then be expected to be another value but is not done correctly for insert.&lt;/P&gt;
&lt;P&gt;Generally with SAS if you need to have double quote character in a value you could use a single quote around the value. But you also have a single quote in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;XML Developer's Guide&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will cause a similar issue. When you need quotes as part of a value then enter them twice. Also the Values expects a () around the value .&lt;/P&gt;
&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table A (Requested_XML varchar(3000));

proc sql;
	insert into A values
("&amp;lt;?xml version=""1.0""?&amp;gt;&amp;lt;catalog&amp;gt;   &amp;lt;book id=""bk101""&amp;gt;      &amp;lt;author&amp;gt;Gambardella, Matthew&amp;lt;/author&amp;gt;      &amp;lt;title&amp;gt;XML Developer''s Guide&amp;lt;/title&amp;gt;      &amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;      &amp;lt;price&amp;gt;44.95&amp;lt;/price&amp;gt;      &amp;lt;publish_date&amp;gt;2000-10-01&amp;lt;/publish_date&amp;gt;      &amp;lt;description&amp;gt;An in-depth look at creating applications  with XML.&amp;lt;/description&amp;gt;   &amp;lt;/book&amp;gt;");
quit;&lt;/PRE&gt;
&lt;P&gt;Personally I would not use INSERT at all. A data step reading a text file is likely to be easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874679#M38823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-09T15:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL.. .How to insert the following XML as string?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874684#M38824</link>
      <description>&lt;P&gt;Leave the strings in data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example read the string from a file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data strings;
  input xml_string $200.;
datalines4;
&amp;lt;?xml version="1.0"?&amp;gt;&amp;lt;catalog&amp;gt;&amp;lt;book id="bk101"&amp;gt;&amp;lt;author&amp;gt;Gambardella, Matthew&amp;lt;/author&amp;gt;&amp;lt;title&amp;gt;XML Developer's Guide&amp;lt;/title&amp;gt;&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;&amp;lt;price&amp;gt;44.95&amp;lt;/price&amp;gt;&amp;lt;publish_date&amp;gt;2000-10-01&amp;lt;/publish_date&amp;gt;&amp;lt;description&amp;gt;An in-depth look at creating applications  with XML.&amp;lt;/description&amp;gt;&amp;lt;/book&amp;gt;
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you then want to insert that value into another dataset you can just use code instead of string literals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
insert into A (select xml_string from strings);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you then need to use the data to generate code you can use the QUOTE() function.&amp;nbsp; For example you could put the quoted string into a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set strings;
  call symputx('mvar',quote(trim(xml_string),"'"));
run;
proc sql;
insert into A values (&amp;amp;mvar);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-How-to-insert-the-following-XML-as-string/m-p/874684#M38824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-09T15:47:49Z</dc:date>
    </item>
  </channel>
</rss>

