XML file generation with line break

Reply
Super Contributor
Posts: 625

XML file generation with line break

[ Edited ]

I've a dataset which has only this variable called 'X' and it has value as Fraais:<BR/>indexion<BR/>Vlams:<BR/>indetie

 

I've to convert this dataset to XML file which should have contents as follows. I'm not certain how to instruct SAS to treat each line break (<BR/&gtSmiley Wink to enter the text in next line.

 

<explanation>Fraais:
indexion
Vlams:
indetie </explanation>

Super User
Posts: 10,228

Re: XML file generation with line break

Individual put statements will always cause a newline in the text file:

data _null_;
file '$HOME/sascommunity/babloo.xml';
put '<explanation>Franc:';
put 'indexat';
put 'Vlaam:';
put 'indexae </explanation>';
run;

Resulting file:

<redacted>/sascommunity $ cat babloo.xml
<explanation>Franc:
indexat
Vlaam:
indexae </explanation>
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 625

Re: XML file generation with line break

Posted in reply to KurtBremser

I should have asked the question in this way. I've a dataset which has only this variable called 'X' and it has value as Fraais:&lt;BR/&gt;indexion&lt;BR/&gt;Vlams:&lt;BR/&gt;indetie

 

I've to convert this dataset to XML file which should have contents as follows. I'm not certain how to instruct SAS to treat each line break (&lt;BR/&gtSmiley Wink to enter the text in next line.

 

<explanation>Fraais:
indexion
Vlams:
indetie </explanation>

Super User
Posts: 10,228

Re: XML file generation with line break

See if this: https://stackoverflow.com/questions/35504890/how-to-add-a-newline-line-break-in-xml-file can give you useful hints.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 625

Re: XML file generation with line break

Posted in reply to KurtBremser

Given link deals with only XML part and not from SAS with XML. Also I'm not certain to fit guidelines mentioned in the link below to my SAS program.

Super User
Posts: 10,228

Re: XML file generation with line break


Babloo wrote:

Given link deals with only XML part and not from SAS with XML. Also I'm not certain to fit guidelines mentioned in the link below to my SAS program.


Just add the suggested strings to your put statements or to the variables you use in the put. Quite simple, very basic data step technique. Should not pose a problem to someone who's already a veteran here (after 500+ posts)

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,599

Re: XML file generation with line break

data want;
  str='Fraais:&lt;BR/&gt;indexion&lt;BR/&gt;Vlams:&lt;BR/&gt;indetie';
  str=tranwrd(str,'&lt;BR;/&gt;','0A'x);
run;
Super Contributor
Posts: 625

Re: XML file generation with line break

It has not resolved the issue either. I'm getting the same value in row instead of multiple rows.

Super User
Super User
Posts: 9,599

Re: XML file generation with line break

Just saying it didn't work doesn't help.  Show your code, is it possible your doing this on Windows and opening in Notepad, then you likely need to replace with Linefeed + CR characters as that is Windows standard.  I can't guess!

Super Contributor
Posts: 625

Re: XML file generation with line break

I just added the following two lines in my SAS program which creates the XML file and ran it via SAS EG. After the successful run, I could see that XML file has generated with the below highlighted part in one line instead of 4 lines.

 

 str='Fraais:&lt;BR/&gt;indexion&lt;BR/&gt;Vlams:&lt;BR/&gt;indetie';
  str=tranwrd(str,'&lt;BR;/&gt;','0A'x);

 

Super User
Posts: 10,228

Re: XML file generation with line break

If you just put str to the text file, it's contents will be in one line. If you want the lines to break, use several put statements, as I already told you.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,599

Re: XML file generation with line break

Not sure why you would want to, visually it does not matter as the whole text between the two tags is read in, you will just end up with linefeeds if you force them in.

<explanation>
  Franc: indexat Vlaam: indexae
</explanation>

Is effecively what the XML should look like.  If you want Franc and Vlam separated then these should come under separate tags:

<explanation>
  <Franc> indexat </Franc>
<Vlaam> indexae </Vlaam> </explanation>

Anyways if you continue, in your data you can add the hex character '0A'x to give returns like:

data want;
  set have;
  substr(line,14,1)='0A'x;
run;

 

Ask a Question
Discussion stats
  • 11 replies
  • 231 views
  • 3 likes
  • 3 in conversation