Syntax, CALL SYMPUTX
routine:
CALL SYMPUTX(macro-variable-name, value <,symbol-table>);
macro-variable-name
is assigned the character
value ofexpression, and any
leading or trailing blanks are removed from both macro
variable and expression.
macro-variable and expression
can each be specified
as one of the following items:
value
is the value to be
assigned, which can be any of these items:
symbol-table
specifies a character
constant, variable, or expression. The value of symbol-table is
not case sensitive. The first non-blank character in symbol-table specifies
the symbol table in which to store the macro variable. The following
values are valid as the first non-blank character in symbol-table:
G
specifies that the
macro variable is stored in the global symbol table, even if the local
symbol table exists.
L
specifies that the
macro variable is stored in the most local symbol table that exists.
That is the global symbol table, if it is used outside a macro.
F
specifies that if the
macro variable exists in any symbol table, CALL SYMPUTX uses the version
in the most local symbol table in which it exists. If the macro variable
does not exist, CALL SYMPUTX stores the variable in the most local
symbol table.
|
%let crsnum=3; data revenue; set certadv.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;
options symbolgen pagesize=30; %let crsnum=3; data revenue; set certadv.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 symputx('foot','Some Fees Are Unpaid'); end; else do; call symputx('foot','All Students Have Paid'); end; end; run; proc print data=work.revenue; var student_name student_company paid; title "Payment Status for Course &crsnum"; footnote "&foot"; run;
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.%let crsnum=3; data revenue; set certadv.all end=final; where course_number=&crsnum; total+1; if paid='Y' then paidup+1; if final then do; call symputx('numpaid',paidup); call symputx('numstu',total); call symputx('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;
data _null_;
set certadv.courses;
call symputx(course_code,course_title);
run;
%put _user_;
GLOBAL A one:two-three four GLOBAL C001 Basic Telecommunications GLOBAL C002 Structured Query Language GLOBAL C003 Local Area Networks GLOBAL C004 Database Design GLOBAL C005 Artificial Intelligence GLOBAL C006 Computer Aided Design GLOBAL CRSNAME Local Area Networks GLOBAL CRSNUM 3 GLOBAL DELIM GLOBAL NUMPAID 14 GLOBAL NUMSTU 20 GLOBAL PATH C:Userscertadv GLOBAL STRING william SMITH
%let crsid=C005; proc print data=certadv.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &c005"; run;
%let crsid=C002; proc print data=certadv.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &c002"; run;
Syntax, 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 that determines these details:
source and format.
must be the same type
(numeric or character).
|
%let crsnum=3;
data revenue;
set certadv.all end=final;
where course_number=&crsnum;
total+1;
if paid='Y' then paidup+1;
if final then do;
call symputx('crsname',trim(course_title));
call symputx('date',put(begin_date,mmddyy10.));
call symputx('due',strip(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;