Carrige返回,带有put语句的选项卡

时间:2018-10-04 13:24:22

标签: sas

我想使用数据步骤put语句编写一些html和javascript代码。虽然我可以使生成的html文件在浏览器中看起来像我想要的样子,但我不知道如何在SAS EG和生成的文件中轻松读取代码。

我希望生成的文件包含回车符,制表符等,但希望避免在每行中都加上引号。另外,我需要它在宏中运行。我在下面做了一些尝试。这是将ex的可读结果结合在一起的简便方法。 2和ex。 3与ex的简化。 1,喜欢设置选项吗?

/*  Ex 1: Easy to read in SAS EG, but no tabs or carrige returns in html-file*/
data _null_;
    file "C:\Test\test1.html" encoding="utf-8" ;
    put "   Some code
            Some code on a new line
                Some indented code";
run;

/*  Ex 2: Tabs and line breaks in html file, but far more cumbersome to write in SAS EG.*/
data _null_;
    file "C:\Test\test2.html" encoding="utf-8";
    put @4  "Some code" /
        @4  "Some code on a new line" /
        @8  "Some indented code";
run;

/*  Ex 3: Easy to read and write in SAS EG, reads well in html file. But won't run in a macro, and resolving macro variables is more trouble than with the methods above.*/
data _null_;
    input  ;
    file "C:\Test\test3.html" encoding="utf-8";
    put _infile_;
datalines;
Some code
Some code on a new line
    Some indented code
;
run;

2 个答案:

答案 0 :(得分:2)

对于数字3,您可以使用PARMCARDS和RESOLVE功能。

filename FT15F001 temp;
parmcards4;
Some code
Some code on a new line &sysdate
    Some indented code
;;;;


%macro main;
   data _null_;
      infile FT15F001;
      input;
      file "C:\Test\test3.html" encoding="utf-8";
      _infile_ = resolve(_infile_);
      put _infile_;
      run;
   %mend;
%main;

答案 1 :(得分:0)

汤姆的评论建议我应该使用PROC STREAM。事实证明,这种方式比使用陈述式的变更要容易得多。一个简化的示例并不能完全做到这一点,但是此过程使编写这种代码成为可能,而不必花费大量的时间来引用正确的代码。我仍然需要使用&streamDelim newline;来换行,但这是一个很小的代价。当前设置示例;

/*  Ex 4. Proc stream*/
%macro chartx();
%let cr=%str(&streamDelim newline;);
Some code                       &cr
Some code on a new line         &cr
Some code on a new line, with resolved macro variable &sysdate &cr
    some indented code &cr
%do i=1 %to 1;
Some code from a loop
%end;
%mend;

%macro makepage();

filename testfile "C:\Test\test4.html";

proc stream outfile=testfile;
BEGIN
%chartx
;;;;
%mend;
%makepage