foot
. Then foot
is
referenced in the FOOTNOTE statement later in the program.
options symbolgen pagesize=30; %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; put total= paidup=; /* Write information to the log. */ if paidup<total then do; %let foot=Some Fees Are Unpaid; end; else do; %let foot=All Students Have Paid; end; end; run; proc print data=revenue; var student_name student_company paid; title "Payment Status for Course &crsnum"; footnote "&foot"; run;
foot
resolves to the
value All Students Have Paid
when it
should not do so. Look at the following example.
foot
.
Then foot
is referenced in the FOOTNOTE statement
later in the program.
options symbolgen pagesize=30; %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; put total= paidup=; /* Write information to the log. */ if paidup<total then do; %let foot=Some Fees Are Unpaid; end; else do; %let foot=All Students Have Paid; end; end; run; proc print data=revenue; var student_name student_company paid; title "Payment Status for Course &crsnum"; footnote "&foot"; run;
foot
in
the symbol table and assigns the value Some Fees Are
Unpaid
to the variable.
All Students Have Paid
to foot
in
the symbol table.
foot
is always whatever the last %LET
statement assigns.
data revenue; set sasuser.all end=final; where course_number=3; total+1; if paid='Y' then paidup+1; if final then do; put total= paidup=; if paidup<total then do; end; else do; end; end; run; proc print data=revenue; var student_name student_company paid; title "Payment Status for Course 3"; footnote "All Students Have Paid"; run; |
General form, SYMPUT
routine:
CALL SYMPUT(macro-variable,text);
macro-variable
is assigned the character
value of text.
macro-variable and text
can each be specified
as
|
foot
based on values that
are generated during DATA step execution. You can use the SYMPUT routine
with literal strings as both arguments in order to accomplish this.
options symbolgen pagesize=30; %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; if paidup<total then do; call symput('foot','Some Fees Are Unpaid'), end; else do; call symput('foot','All Students Have Paid'), end; end; run; proc print data=revenue; var student_name student_company paid; title "Payment Status for Course &crsnum"; footnote "&foot"; run;
foot
is either Some
Fees Are Unpaid
or All Students Have
Paid
, depending on the value of the DATA step variable Paidup
,
because the value is assigned during the execution of the DATA step.
When you submit this code, you get the following output.
paidup
records the number
of students that have paid, and a DATA step variable named total
records
the total number of students who are registered for the class. Macro
variables are created to record the values of paidup
,
the value of total
, and the value of Course_title
.
These macro variables are referenced later in the program. %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;
Fee Status for Local Area Networks (#3) Student_Name Student_Company Paid Bills, Ms. Paulette Reston Railway Y Chevarley, Ms. Arlene Motor Communications N Clough, Ms. Patti Reston Railway N Crace, Mr. Ron Von Crump Seafood Y Davis, Mr. Bruce Semi;Conductor Y Elsins, Ms. Marisa F. SSS Inc. N Gandy, Dr. David Paralegal Assoc. Y Gash, Ms. Hedy QA Information Systems Center Y Haubold, Ms. Ann Reston Railway Y Hudock, Ms. Cathy So. Cal. Medical Center Y Kimble, Mr. John Alforone Chemical N Kochen, Mr. Dennis Reston Railway Y Larocque, Mr. Bret Physicians IPA Y Licht, Mr. Bryan SII Y McKnight, Ms. Maureen E. Federated Bank Y Scannell, Ms. Robin Amberly Corp. N Seitz, Mr. Adam Lomax Services Y Smith, Ms. Jan Reston Railway N Sulzbach, Mr. Bill Sailbest Ships Y Williams, Mr. Gene Snowing Petroleum Y Note: 14 Paid out of 20 Students |
crsname
,
you can use the TRIM function. To remove leading and trailing blanks
from the macro variables numstu
and numpaid
,
you can use the STRIP function.%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',strip(paidup)); call symput('numstu',strip(total)); call symput('crsname',trim(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;
Fee Status for Local Area Networks (#3) NAME COMPANY PAID Bills, Ms. Paulette Reston Railway Y Chevarley, Ms. Arlene Motor Communications N Clough, Ms. Patti Reston Railway N Crace, Mr. Ron Von Crump Seafood Y Davis, Mr. Bruce Semi;Conductor Y Elsins, Ms. Marisa F. SSS Inc. N Gandy, Dr. David Paralegal Assoc. Y Gash, Ms. Hedy QA Information Systems Center Y Haubold, Ms. Ann Reston Railway Y Hudock, Ms. Cathy So. Cal. Medical Center Y Kimble, Mr. John Alforone Chemical N Kochen, Mr. Dennis Reston Railway Y Larocque, Mr. Bret Physicians IPA Y Licht, Mr. Bryan SII Y McKnight, Ms. Maureen E. Federated Bank Y Scannell, Ms. Robin Amberly Corp. N Seitz, Mr. Adam Lomax Services Y Smith, Ms. Jan Reston Railway N Sulzbach, Mr. Bill Sailbest Ships Y Williams, Mr. Gene Snowing Petroleum Y Note: 14 Paid out of 20 Students |
General form, PUT function:
PUT(source,format.)
source
is a constant, a variable,
or an expression (numeric or character).
format.
is any SAS format or
user-defined format, which determines
source and format.
must be the same type
(numeric or character).
|
Begin_date
with
the MMDDYY10. format and assign that value to the macro variable date
.
Then you also use another call to the SYMPUT routine to format the
result of an expression involving Fee
, total
,
and paidup
as a dollar amount and assign
that value to the macro variable due
. %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('crsname',trim(course_title));
call symput('date',put(begin_date,mmddyy10.));
call symput('due',strip(put(fee*(total-paidup),dollar8.)));
end;
run;
date
and due
in
a PROC PRINT step to create your report. The values of these macro
variables appear in the report with the formatting that you assigned
to them when you created them. proc print data=revenue; var student_name student_company paid; title "Fee Status for &crsname (#&crsnum) Held &date"; footnote "Note: &due in Unpaid Fees"; run;
General form, SYMPUTX
routine:
CALL SYMPUTX(macro-variable,expression);
macro-variable
is assigned the character
value of expression, and any
leading or trailing blanks are removed from both macro-variable and expression.
macro-variable and expression
can each be specified
as
|
csrname
records
the value of the DATA step variable Course_title
.
The macro variable date
records the value
of the DATA step variable Begin_date
in MMDDYY10.
format. Finally, the macro variable due
uses
the values of the DATA step variables paidup
, total
,
and fee
to record the current amount of unpaid
fees in DOLLAR8. format. These macro variables are referenced later
in the program in the title and footnote statements. %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 symputx('crsname',course_title); call symputx('date',put(begin_date,mmddyy10.)); call symputx('due',put(fee*(total-paidup),dollar8.)); end; run; proc print data=revenue; var student_name student_company paid; title "Fee Status for &crsname (#&crsnum) Held &date"; footnote "Note: &due in Unpaid Fees"; run;