![]() | ![]() | ![]() | ![]() | ![]() |
The sample code on the Full Code tab illustrates how to assign DATA step information to a macro variable using CALL SYMPUTX.
Calculate the total weight of all students in SASHELP.CLASS. Create a macro variable using each student name to contain the student's weight and a macro variable called S_TOT to contain the total combined weight of the class.
Note: CALL SYMPUTX is new in SAS 9.0. Below are four features of CALL SYMPUTX.
1.) CALL SYMPUTX does not write a note to the SAS log when the second argument is numeric. CALL SYMPUT, however, writes a note to the log stating that numeric values were converted to character values.
2.) CALL SYMPUTX uses a field width of up to 32 characters when it converts a numeric second argument to a character value. CALL SYMPUT uses a field width of up to 12 characters.
3.) CALL SYMPUTX left-justifies both arguments and trims trailing blanks. CALL SYMPUT does not left-justify the arguments, and trims trailing blanks from the first argument only. Leading blanks in the value of name cause an error.
4.) CALL SYMPUTX enables you to specify the symbol table in which to store the macro variable, whereas CALL SYMPUT does not. This is accomplished by an optional third argument to the SYMPUTX function.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
%macro drive(class,var);
proc means data=sashelp.class noprint;
class &class;
var &var;
output out=stats sum=s_sal;
run;
data _null_;
set stats;
if _n_=1 then call symputx('s_tot',s_sal,'g');
else call symputx('s_'||name,s_sal,'g');
run;
%mend drive;
%drive(name,weight)
/* Write all global macro variables to LOG */
%put _user_;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
OUTPUT to SAS log GLOBAL S_BARBARA 98 GLOBAL S_LOUISE 77 GLOBAL S_JEFFREY 84 GLOBAL S_ROBERT 128 GLOBAL S_JANE 84.5 GLOBAL S_WILLIAM 112 GLOBAL S_TOT 1900.5 GLOBAL S_JOHN 99.5 GLOBAL S_HENRY 102.5 GLOBAL S_JAMES 83 GLOBAL S_MARY 112 GLOBAL S_PHILIP 150 GLOBAL S_THOMAS 85 GLOBAL S_CAROL 102.5 GLOBAL S_JOYCE 50.5 GLOBAL S_ALFRED 112.5 GLOBAL S_JANET 112.5 GLOBAL S_ALICE 84 GLOBAL S_JUDY 90 GLOBAL S_RONALD 133
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> CALL routines |
| Date Modified: | 2005-12-08 11:34:32 |
| Date Created: | 2004-09-30 14:09:12 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | Tru64 UNIX | 9 TS M0 | n/a |
| OpenVMS Alpha | 9 TS M0 | n/a | ||
| HP-UX IPF | 9 TS M0 | n/a | ||
| Linux | 9 TS M0 | n/a | ||
| 64-bit Enabled Solaris | 9 TS M0 | n/a | ||
| 64-bit Enabled HP-UX | 9 TS M0 | n/a | ||
| 64-bit Enabled AIX | 9 TS M0 | n/a | ||
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | n/a | ||
| z/OS | 9 TS M0 | n/a | ||




