mj023119
mj023119

Reputation: 675

How to add carriage return in SAS code?

I want to add a carriage return\linebreak\linefeed to the SAS code, so that there are returns in the output xml.

data test_JK_merge;
    length body $ 1500;
    set test_JK;
    body=strip(termEntry_st)||"
"||strip(TS_Status)||strip(langset_en_st)||strip(nttG)||strip(langset_en_ed)||strip(termEntry_ed);
    /*merged=strip(termEntry_st)||"'0A'X"||strip(TS_Status)||"<br />"||strip(langset_en_st)||"<br />"||strip(nttG)||"<br />"||strip(langset_en_ed)||"<br />"||strip(termEntry_ed);*/
    keep body;
run;

libname outxml xml "U:\Projects\...\test2.mtf.xml";

data outxml.text;
    set test_JK_merge;
run;

I have tried different ways, such as &#13;, 'OA'X, &#10;,<br />etc But none of them worked. Does anybody can help out?

Actual result:

<TEXT>
  <body><termEntry id=1>&#13;<note type="TS_Status">ELC TERM present in OCS_Help_xml OCS_properties</note><langSet lang="eng-us">ntig><termGrp><term>ARM</term></termGrp></ntig></langSet></termEntry></body> 
 </TEXT>

Expected result:

    <TEXT>
      <body><termEntry id=1>
<note type="TS_Status">ELC TERM present in OCS_Help_xml OCS_properties</note><langSet lang="eng-us">ntig><termGrp><term>ARM</term></termGrp></ntig></langSet></termEntry></body> 
     </TEXT>

Upvotes: 3

Views: 8670

Answers (1)

Tom Quarendon
Tom Quarendon

Reputation: 5718

I'm actually slightly surprised that you get

<body><termEntry ...

by using LIBNAME XML. I might be inclined to generate the XML manually from a DATA step.

LIBNAME XML with style=generic (the default) will produce output of the form

<dsname>
   <columnname>column value</columnname>
</dsname>
<dsname>
   <columnname>column value</columnname>
</dsname>
..etc...

i.e one tag <dsname> for each record in your input file with a tag under it for each variable in the data set. In order that SAS can then read the result back in it will escape any value, so that if the variable in the data set is a string and contains any of the characters <, & etc it won't "confuse" the XML. So in your case, where the variable in the data set has a value something like

<termEntry id=1>...</termEntry>

then I'd expect the output from libname XML to be something like

<TEXT>
    <body> &lt;termEntry id=1&gt;&lt;/termEntry&gt; </body>
</TEXT

The options seem to be either to understand how to use XMLMap with LIBNAME XML in order to generate the XML you want (may not be possible depending on what version of SAS you have), or to generate the XML manually using a DATA step:

data test_JK;
    termEntry_st = "<termEntry id=1>";
    termEntry_ed = "</termEntry>";
    TS_Status = "<note type='TS_Status'>ELC TERM present in OCS_Help_xml OCS_properties</note>";
    langset_en_st = "<langSet lang='eng-us'>";
    langset_en_ed = "</langSet>";
    nttG = "<ntig><termGrp><term>ARM</term></termGrp></ntig>";

data _null_;
    set test_JK end=e;
    file "tmp.xml";

    if _n_ eq 1 then do;
       put "<something>";
    end;

    put "  <text>";
    put "    <body>" +(-1) termEntry_st;
    put TS_Status +(-1) langset_en_st +(-1) nttG +(-1) langset_en_ed +(-1) termEntry_ed  + (-1) "</body>";
    put "  </text>";

    if e then do;
       put "</something>";
    end;
 run;

Upvotes: 3

Related Questions