关于SAS变量默认初始化值的问题

发布于 2024-10-14 14:56:59 字数 791 浏览 3 评论 0原文

我对以下 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 技术交流群。

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

发布评论

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

评论(1

傾旎 2024-10-21 14:56:59

第一个问题:是的,这就是 SAS 所做的 - 它用 0 初始化变量,并在数据集循环中“保留”变量的值。 (除非变量 payup 已存在于源数据中,在您的情况下为 sasuser.all)

第二个问题:在您发布的代码中,#:它将作为文字出现在标题中 &crsnum 的解析值之前。因此,如果 &crsname 为 Blah 并且 &crsnum 为 3,标题将显示为

Blah 的费用状态 (#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 read

Fee Status for Blah (#3)

The # 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'.

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