I'm just curious why you're not using the XML libname engine or the DATA step to write what you want.
put @1 '';
If you look at the file, c:\temp\fakexml.xml with Notepad, you will see your one line without extra quotes and without any header. FYI, your initially posted SQL has several syntax issues that should be producing errors in your SAS log (2 CREATE keywords and semi-colon in the wrong place).
You say you want to insert some XML into a "little table" -- is that little table in CSV format??? How did you create the table? What does it look like? It is possible in a DATA step program to write a line only 1 time (such as at the top of a file) but you haven't provided much information to go on.
You say you want to insert some XML into a "little table" -- is that little table in CSV format???
Lee>The source table contained one variable and one record. The xml string is hardcoded apart from one bit,which is a variable.
How did you create the table?
Lee>I create the table in the code attached. Just one column, one record.
Your programmed worked
6912 data _null_;
6913 file "C:\temp\test.xml";
6914 put @1 'xyz';
NOTE: The file "C:\temp\test.xml" is:
NOTE: 1 record was written to the file "C:\temp\test.xml".
But when I change it to support variable input and change the outside quotes to double quotes it has a problem with this solution.
Even though you can write your XML as one long quoted string, as you discovered, double quotes inside double quotes lead to other issues in the SAS code. So, there's nothing wrong with writing part of the string in SINGLE quotes and then part of the string in DOUBLE quotes, so the macro variable resolves correctly and you do not get quoting issues in the compiler.
put @1 ''
produces this outout in the c:\temp\fakexml.xml file:
<test><testdo yyy="abc"><test1 xxx="x">abc</test1></testdo></test>
You could also use syntax in your DATA step program like this (I know, this isn't valid XML, but I was more interested in showing a couple of different quoting possibilities with the macro variable):
. . . more code . . .
put '** Another example';
put @1 '<wombat>'
'<test1 koala="' "&test&test" '">wombat</test1>';
to produce this output in the file created by the PUT statements:
** Another example
Log from the complete program is shown below.
88 %let test=abc;
89 data _null_;
90 file 'c:\temp\fakexml.xml';
91 put @1 '<test><testdo yyy="abc"><test1 xxx="x">'
94 put '** Another example';
95 put @1 '<wombat>'
97 '<test1 koala="' "&test&test" '">wombat</test1>';
NOTE: The file 'c:\temp\fakexml.xml' is:
RECFM=V,LRECL=256,File Size (bytes)=0,
NOTE: 3 records were written to the file 'c:\temp\fakexml.xml'.
The minimum record length was 18.
The maximum record length was 66.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds