BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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>

11 REPLIES 11
Kurt_Bremser
Super User

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>
Babloo
Rhodochrosite | Level 12

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/&gt;) to enter the text in next line.

 

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

Babloo
Rhodochrosite | Level 12

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.

Kurt_Bremser
Super User

@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)

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26
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;
Babloo
Rhodochrosite | Level 12

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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!

Babloo
Rhodochrosite | Level 12

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);

 

Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 3098 views
  • 3 likes
  • 3 in conversation