Chapter Contents |
Previous |
Next |
SYMGET |
Type: | SAS language function | ||||
See also: |
|
Syntax | |
Details | |
Comparisons | |
Example | |
Retrieving Variable Values Previously Assigned from a Data Set |
Syntax |
SYMGET(argument) |
x=symget('g');
length key $ 8; input code $; key=symget(code);
Each time the DATA step iterates, the value of CODE supplies the name of a macro variable whose value is then assigned to KEY.
s
and the number of the
current iteration (using the automatic DATA step variable _N_).
score=symget('s'||left(_n_));
Details |
SYMGET returns a character value that is the maximum length of a DATA step character variable. A returned value that is longer is truncated.
If SYMGET cannot locate the macro variable identified as the argument, it returns a missing value, and the program issues a message for an illegal argument to a function.
SYMGET can be used in all SAS language programs, including SCL programs. Because it resolves variables at program execution instead of macro execution, SYMGET should be used to return macro values to DATA step views, SQL views, and SCL programs.
Comparisons |
Example |
data dusty; input dept $ name $ salary @@; cards; bedding Watlee 18000 bedding Ives 16000 bedding Parker 9000 bedding George 8000 bedding Joiner 8000 carpet Keller 20000 carpet Ray 12000 carpet Jones 9000 gifts Johnston 8000 gifts Matthew 19000 kitchen White 8000 kitchen Banks 14000 kitchen Marks 9000 kitchen Cannon 15000 tv Jones 9000 tv Smith 8000 tv Rogers 15000 tv Morse 16000 ; proc means noprint; class dept; var salary; output out=stats sum=s_sal; run; proc print data=stats; var dept s_sal; title "Summary of Salary Information"; title2 "For Dusty Department Store"; run; data _null_; set stats; if _n_=1 then call symput('s_tot',s_sal); else call symput('s'||dept,s_sal); run; data new; set dusty; pctdept=(salary/symget('s'||dept))*100; pcttot=(salary/&s_tot)*100; run; proc print data=new split="*"; label dept ="Department" name ="Employee" pctdept="Percent of *Department* Salary" pcttot ="Percent of * Store * Salary"; format pctdept pcttot 4.1; title "Salary Profiles for Employees"; title2 "of Dusty Department Store"; run;
This program produces the output shown in Intermediate Data Set and Final Report.
Intermediate Data Set and Final Report
Summary of Salary Information 1 For Dusty Department Store OBS DEPT S_SAL 1 221000 2 bedding 59000 3 carpet 41000 4 gifts 27000 5 kitchen 46000 6 tv 48000 Salary Profiles for Employees 2 Dusty Department Store Percent of Percent of Department Store OBS Department Employee SALARY Salary Salary 1 bedding Watlee 18000 30.5 8.1 2 bedding Ives 16000 27.1 7.2 3 bedding Parker 9000 15.3 4.1 4 bedding George 8000 13.6 3.6 5 bedding Joiner 8000 13.6 3.6 6 carpet Keller 20000 48.8 9.0 7 carpet Ray 12000 29.3 5.4 8 carpet Jones 9000 22.0 4.1 9 gifts Johnston 8000 29.6 3.6 10 gifts Matthew 19000 70.4 8.6 11 kitchen White 8000 17.4 3.6 12 kitchen Banks 14000 30.4 6.3 13 kitchen Marks 9000 19.6 4.1 14 kitchen Cannon 15000 32.6 6.8 15 tv Jones 9000 18.8 4.1 16 tv Smith 8000 16.7 3.6 17 tv Rogers 15000 31.3 6.8 18 tv Morse 16000 33.3 7.2 |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.