卡里格返回,带有放置语句的选项卡

  • 本文关键字:语句 选项 返回 sas
  • 更新时间 :
  • 英文 :


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

我希望生成的文件具有 carrige 返回、制表符等,但希望避免在每一行中添加引号。另外,我需要它在宏中运行。我在下面包括了一些尝试。将例 2 和例 3 的可读结果与例 1 的 coidng 易用性相结合,就像设置选项一样,这是一种简单的方法吗?

/*  Ex 1: Easy to read in SAS EG, but no tabs or carrige returns in html-file*/
data _null_;
file "C:Testtest1.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:Testtest2.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:Testtest3.html" encoding="utf-8";
put _infile_;
datalines;
Some code
Some code on a new line
Some indented code
;
run;

对于数字 3,您可以使用 PARMCARD 和 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:Testtest3.html" encoding="utf-8";
_infile_ = resolve(_infile_);
put _infile_;
run;
%mend;
%main;

Tom 的评论建议我应该使用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:Testtest4.html";
proc stream outfile=testfile;
BEGIN
%chartx
;;;;
%mend;
%makepage

最新更新