<?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: How to: create an xml file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778253#M247718</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;In the program, it is written "set work.report end=eof1;" I accidentally wrote eof.&lt;BR /&gt;&lt;BR /&gt;If I delete these 2 lines I get xml but not exactly according to the hierarchy I wanted.&lt;BR /&gt;put '&amp;lt;currency dt=" 'currencyid' "&amp;gt;';&lt;BR /&gt;put '&amp;lt;/currency&amp;gt;';&lt;BR /&gt;&lt;BR /&gt;There are no errors in the Log&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not intimately familiar with all the stuff that may be an XML so I don't know what the DT= may mean. If it is related to data type then perhaps you are missing something as the example currencyid values of 00 don't look like a "type" .&lt;/P&gt;</description>
    <pubDate>Wed, 03 Nov 2021 16:38:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-11-03T16:38:03Z</dc:date>
    <item>
      <title>How to: create an xml file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778022#M247621</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I want to create an xml file from a SAS table with a hierarchy.&amp;nbsp;&lt;BR /&gt;The table has the following 10 fields:&lt;BR /&gt;currencyid, value, id, withdrawaldate, withdrawaltime, bankcode, bankbranchcode, monthreport, cuerrentdate, factorcode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example table:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;bankcode&lt;/TD&gt;&lt;TD&gt;bankbranchcode&lt;/TD&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;withdrawaldate&lt;/TD&gt;&lt;TD&gt;withdrawaltime&lt;/TD&gt;&lt;TD&gt;currencyid&lt;/TD&gt;&lt;TD&gt;monthreport&lt;/TD&gt;&lt;TD&gt;cuerrentdate&lt;/TD&gt;&lt;TD&gt;factorcode&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;401&lt;/TD&gt;&lt;TD&gt;12332324&lt;/TD&gt;&lt;TD&gt;2020-09-12&lt;/TD&gt;&lt;TD&gt;12:20:24&lt;/TD&gt;&lt;TD&gt;00&lt;/TD&gt;&lt;TD&gt;2021-10&lt;/TD&gt;&lt;TD&gt;2021-11-01&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;490&lt;/TD&gt;&lt;TD&gt;12342&lt;/TD&gt;&lt;TD&gt;2020-09-13&lt;/TD&gt;&lt;TD&gt;12:08:00&lt;/TD&gt;&lt;TD&gt;00&lt;/TD&gt;&lt;TD&gt;2021-10&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-11-01&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is the code I wrote:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data _null_;
	set work.report end=eof;
	file "&amp;amp;outfile./Report.xml" noprint encoding="utf-8";
        by id;

	if _n_ =1 then
		do;
			put '&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;';
			put '&amp;lt;ATMstockReport&amp;gt;';
			put '&amp;lt;currentDate&amp;gt;' currentDate '&amp;lt;/currentDate&amp;gt;';
			put '&amp;lt;factorCode&amp;gt;' factorCode '&amp;lt;/factorCode&amp;gt;';
			put '&amp;lt;monthReport&amp;gt;' monthReport '&amp;lt;/monthReport&amp;gt;';
			put '&amp;lt;atmsStock&amp;gt;';
		end;
if first.id then
    do;
	put '&amp;lt;action atmId="'id'"&amp;gt;';
	put '&amp;lt;bankCode&amp;gt;' bankCode '&amp;lt;/bankCode&amp;gt;';
	put '&amp;lt;bankBranchCode&amp;gt;' bankBranchCode '&amp;lt;/bankBranchCode&amp;gt;';
        put '&amp;lt;withdrawaldate&amp;gt;' withdrawaldate '&amp;lt;/withdrawaldate&amp;gt;';
        put '&amp;lt;withdrawaltime&amp;gt;' withdrawaltime '&amp;lt;/withdrawaltime&amp;gt;';
	put '&amp;lt;currencyvalue&amp;gt;';
end;

	put '&amp;lt;currency dt=" 'currencyid' "&amp;gt;';
	put '&amp;lt;value&amp;gt;' value '&amp;lt;/value&amp;gt;';
	put '&amp;lt;/currency&amp;gt;';

if last.id then
   do;
	put '&amp;lt;/currencyvalue&amp;gt;';
	put '&amp;lt;/action&amp;gt;';
end;

	if eofl then
		do;
			put '&amp;lt;/atmsStock&amp;gt;';
			put '&amp;lt;/ATMstockReport&amp;gt;';
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After running I get only the first record, something with the sorting of the "currencyid" field is incorrect&amp;nbsp;I think.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shlomiohana_1-1635885427875.jpeg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65330i5F8C69C8B7481F5F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shlomiohana_1-1635885427875.jpeg" alt="shlomiohana_1-1635885427875.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do I need to sort the table before in a certain order?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 20:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778022#M247621</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2021-11-02T20:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to: create an xml file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778033#M247628</link>
      <description>&lt;P&gt;You don't really show what you expect the output to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does your LOG look like for that step? Any interesting notes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion: Open the XML in a TEXT file viewer, not something that attempts to render the xml into a pretty output.&lt;/P&gt;
&lt;P&gt;See if the lines of text you generated are as you expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I doubt that sort order is the issue unless it was enough a problem that the BY would cause an error, such as BY variables not sorted...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code uses END=EOF.&lt;/P&gt;
&lt;P&gt;You then test for the value of EOF1 so this is one thing to consider. It means that one or more tags such as atmsstock and ATMStockReport do not get the close tags they need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 21:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778033#M247628</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-02T21:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to: create an xml file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778053#M247642</link>
      <description>In the program, it is written "set work.report end=eof1;" I accidentally wrote eof.&lt;BR /&gt;&lt;BR /&gt;If I delete these 2 lines I get xml but not exactly according to the hierarchy I wanted.&lt;BR /&gt;put '&amp;lt;currency dt=" 'currencyid' "&amp;gt;';&lt;BR /&gt;put '&amp;lt;/currency&amp;gt;';&lt;BR /&gt;&lt;BR /&gt;There are no errors in the Log</description>
      <pubDate>Tue, 02 Nov 2021 22:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778053#M247642</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2021-11-02T22:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to: create an xml file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778253#M247718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;In the program, it is written "set work.report end=eof1;" I accidentally wrote eof.&lt;BR /&gt;&lt;BR /&gt;If I delete these 2 lines I get xml but not exactly according to the hierarchy I wanted.&lt;BR /&gt;put '&amp;lt;currency dt=" 'currencyid' "&amp;gt;';&lt;BR /&gt;put '&amp;lt;/currency&amp;gt;';&lt;BR /&gt;&lt;BR /&gt;There are no errors in the Log&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not intimately familiar with all the stuff that may be an XML so I don't know what the DT= may mean. If it is related to data type then perhaps you are missing something as the example currencyid values of 00 don't look like a "type" .&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 16:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-xml-file/m-p/778253#M247718</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-03T16:38:03Z</dc:date>
    </item>
  </channel>
</rss>

