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?
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'.
精彩评论