Sas Carrige return,带put语句的制表符
我想使用数据步骤Sas Carrige return,带put语句的制表符,sas,Sas,我想使用数据步骤put语句来编写一些html和javascript代码。虽然我可以让生成的html文件在浏览器中以我想要的方式显示,但我不知道如何让代码在SAS EG和生成的文件中都易于阅读 我希望生成的文件有carrige returns、tabs等,但希望避免在每一行添加引号。另外,我需要它在宏中运行。我在下面列出了一些尝试。将ex.2和ex.3的可读结果与ex.1的易读性结合起来,像设置选项一样,这是一种简单的方法吗 /* Ex 1: Easy to read in SAS EG, bu
put
语句来编写一些html和javascript代码。虽然我可以让生成的html文件在浏览器中以我想要的方式显示,但我不知道如何让代码在SAS EG和生成的文件中都易于阅读
我希望生成的文件有carrige returns、tabs等,但希望避免在每一行添加引号。另外,我需要它在宏中运行。我在下面列出了一些尝试。将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;
对于数字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;
对于数字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;
Tom的评论建议我应该使用
PROC-STREAM
。事实证明,这比使用put语句的变体更容易。一个简化的示例并不能很好地实现这一点,但是这个过程使编写这种代码成为可能,而无需繁琐地正确引用。我仍然需要使用&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
Tom的评论建议我应该使用PROC-STREAM
。事实证明,这比使用put语句的变体更容易。一个简化的示例并不能很好地实现这一点,但是这个过程使编写这种代码成为可能,而无需繁琐地正确引用。我仍然需要使用&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
SAS EG中的#1和#2有什么不同?test1.html写在一行上,因此需要重新格式化以便于阅读。test2.html读起来很好。#2中的引文等在一个简短的、程式化的示例中是可以的,但在实际代码中会变得混乱,你看了PROC STREAM
?没有,但我现在肯定会看。是的,读了一点并测试了一下,看起来PROC STREAM
才是正确的选择。我来找一个类似选项的东西,所以这是我不知道我在找的解决方案。SAS EG中的#1和#2有什么不同?test1.html写在一行上,所以需要重新格式化以便于阅读。test2.html读起来很好。#2中的引文等在一个简短的、程式化的示例中是可以的,但在实际代码中会变得混乱,你看了PROC STREAM
?没有,但我现在肯定会看。是的,读了一点并测试了一下,看起来PROC STREAM
才是正确的选择。我来找一个类似选项的东西,所以这是我不知道我在找的解决方案。非常有趣@AllanBowe你是什么意思?这是一个很好的解决方案。Parmcards对我来说是新事物。但仍然只能在宏中使用data null步骤,而不是全部?PARMCARDS没有记录在“SAS语句字典”中。我在PARMCARDS选项的文档中找到了这一点。SAS将PARMCARDS(或PARMCARDS4)语句之后的所有数据行写入文件,直到遇到一个分号或四个分号的分隔符行为止。然后关闭该文件并使其可供过程读取。数据行没有解析或宏扩展。@符文您可以将整个程序放在自动调用库中,就像我在自动调用库中编写的一样,它可以工作。AUTOCALL是一个奇特的%INC,代码没有违反%INC的规则。非常有趣@AllanBowe你是什么意思?这是一个很好的解决方案。Parmcards对我来说是新事物。但仍然只能在宏中使用data null步骤,而不是全部?PARMCARDS没有记录在“SAS语句字典”中。我在PARMCARDS选项的文档中找到了这一点。SAS将PARMCARDS(或PARMCARDS4)语句之后的所有数据行写入文件,直到遇到一个分号或四个分号的分隔符行为止。然后关闭该文件并使其可供过程读取。数据行没有解析或宏扩展。@符文您可以将整个程序放在自动调用库中,就像我在自动调用库中编写的一样,它可以工作。自动调用为%INC,代码没有违反%INC的规则。