关于SAS变量默认初始化值的问题
我对以下 SAS 代码有两个问题:
%let crsnum=3;
data revenue;
set sasuser.all end=final;
where course_number=&crsnum;
total+1;
if paid=’Y’ then paidup+1;
if final then do;
call symput(’numpaid’,paidup);
call symput(’numstu’,total);
call symput(’crsname’,course_title);
end;
run;
proc print data=revenue noobs;
var student_name student_company paid;
title "Fee Status for &crsname (#&crsnum)";
footnote "Note: &numpaid Paid out of &numstu Students";
run;
第一个问题,在第 5 行中,它的
if paid=’Y’ then paidup+1;
“paidup”应该是这里的一个变量。 在我看来,SAS 将“paidup”的默认初始值设置为 0。这是真的吗?
的代码段中
title "Fee Status for &crsname (#&crsnum)";
第二个问题,在#&crsnum如何工作? 或者说#这里的功能是什么?
I am having two questions on the following SAS code:
%let crsnum=3;
data revenue;
set sasuser.all end=final;
where course_number=&crsnum;
total+1;
if paid=’Y’ then paidup+1;
if final then do;
call symput(’numpaid’,paidup);
call symput(’numstu’,total);
call symput(’crsname’,course_title);
end;
run;
proc print data=revenue noobs;
var student_name student_company paid;
title "Fee Status for &crsname (#&crsnum)";
footnote "Note: &numpaid Paid out of &numstu Students";
run;
First question, in line 5, it has
if paid=’Y’ then paidup+1;
"paidup" should be a variable here.
It seems to me that SAS setup the default initial value of "paidup" as 0. Is that true?
Second question, in the code segment of
title "Fee Status for &crsname (#&crsnum)";
How does #&crsnum work? Or what's the functionality of # here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题:是的,这就是 SAS 所做的 - 它用 0 初始化变量,并在数据集循环中“保留”变量的值。 (除非变量 payup 已存在于源数据中,在您的情况下为 sasuser.all)
第二个问题:在您发布的代码中,
#
:它将作为文字出现在标题中&crsnum
的解析值之前。因此,如果 &crsname 为 Blah 并且 &crsnum 为 3,标题将显示为然而,当
by
组正在播放时,当以特定方式包含在标题中时,# 可能会影响标题 - 请参阅文档 此处,在“插入 BY-”标题下将信息分组为标题”。First question: yes, that's what SAS has done - it has initialised the variable with 0, and 'retains' the value of the variable across data set loops. (Unless the variable paidup already exists in the source data, in your case sasuser.all)
Second question: in the code you've posted, there is nothing special about the
#
: it will appear as a literal before the resolved value of&crsnum
in the title. So if &crsname is Blah and &crsnum is 3, the title will readThe # can, however, affect titles when a
by
group is in play, when included in the title in a particular way - see the documentation here, under the heading 'Inserting BY-Group Information into a Title'.