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/> to enter the text in next line.
<explanation>Fraais:
indexion
Vlams:
indetie </explanation>
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>
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:<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/>) to enter the text in next line.
<explanation>Fraais:
indexion
Vlams:
indetie </explanation>
See if this: https://stackoverflow.com/questions/35504890/how-to-add-a-newline-line-break-in-xml-file can give you useful hints.
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.
@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)
data want; str='Fraais:<BR/>indexion<BR/>Vlams:<BR/>indetie'; str=tranwrd(str,'<BR;/>','0A'x); run;
It has not resolved the issue either. I'm getting the same value in row instead of multiple rows.
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!
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:<BR/>indexion<BR/>Vlams:<BR/>indetie'; str=tranwrd(str,'<BR;/>','0A'x);
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.