如何在SAS代码中添加回车符?

发布于 2024-10-26 04:37:42 字数 1424 浏览 1 评论 0原文

我想在SAS代码中添加回车符\换行符\换行符,以便输出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;

我尝试过不同的方法,例如&#13;、'OA'X、&#10;、
等 但它们都不起作用。有人可以帮忙吗?

实际结果:

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

预期结果:

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

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 , 'OA'X, ,<br />etc
But none of them worked. Does anybody can help out?

Actual 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2024-11-02 04:37:42

实际上,我

<body><termEntry ...

对使用 LIBNAME XML 所获得的结果感到有点惊讶。我可能倾向于从 DATA 步骤手动生成 XML。

style=generic(默认)的 LIBNAME XML 将生成以下形式的输出

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

,即输入文件中的每条记录有一个标记 ,其下有一个针对数据集中的每个变量的标记。为了使 SAS 能够读回结果,它将对任何值进行转义,因此,如果数据集中的变量是字符串并包含任何字符 <& 等它不会“混淆”XML。因此,在您的情况下,如果数据集中的变量具有类似的值

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

,那么我希望 libname XML 的输出类似于

<TEXT>
    <body> <termEntry id=1></termEntry> </body>
</TEXT

这些选项似乎要么了解如何将 XMLMap 与 LIBNAME XML 结合使用才能生成您想要的 XML(可能无法实现,具体取决于您拥有的 SAS 版本),或者使用 DATA 步骤手动生成 XML:

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;

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> <termEntry id=1></termEntry> </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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文