![]() Chapter Contents |
![]() Previous |
![]() Next |
| RETAIN |
| Valid: | in a DATA step |
| Category: | Information |
| Type: | Declarative |
Syntax |
|
RETAIN <element-list(s)
<initial-value(s) |
(initial-value-1) | (initial-value-list-1) > < . . . element-list-n <initial-value-n | (initial-value-n ) | (initial-value-list-n)>>>; |
| Without Arguments |
| Arguments |
To specify an iteration factor and nested sublists for the initial values, use the following format:
<constant-iter-value*> <(>constant value | constant-sublist<)>
| Details |
| Comparisons |
| Examples |
retain month1-month5;
retain month1-month5 1 year 0 a b c 'XYZ';
XYZ.
retain month1-month5 (1);
Variables MONTH2 through MONTH5 are set to missing initially.
retain _all_;
data _null_;
array City{3} $ City1-City3;
array cp{3} Citypop1-Citypop3;
retain Year Taxyear 1997 City ' '
cp (10000,50000,100000);
file file-specification print;
put 'Values at beginning of DATA step:'
/ @3 _all_ /;
input Gain;
do i=1 to 3;
cp{i}=cp{i}+Gain;
end;
put 'Values after adding Gain to city populations:'
/ @3 _all_;
datalines;
5000
10000
;
The initial values assigned by RETAIN are as follows:
Here are the lines written by the PUT statements:
Values at beginning of DATA step: City1= City2= City3= Citypop1=10000 Citypop2=50000 Citypop3=100000 Year=1997 Taxyear=1997 Gain=. i=. _ERROR_=0 _N_=1 Values after adding GAIN to city populations: City1= City2= City3= Citypop1=15000 Citypop2=55000 Citypop3=105000 Year=1997 Taxyear=1997 Gain=5000 i=4 _ERROR_=0 _N_=1 Values at beginning of DATA step: City1= City2= City3= Citypop1=15000 Citypop2=55000 Citypop3=105000 Year=1997 Taxyear=1997 Gain=. i=. _ERROR_=0 _N_=2 Values after adding GAIN to city populations: City1= City2= City3= Citypop1=25000 Citypop2=65000 Citypop3=115000 Year=1997 Taxyear=1997 Gain=10000 i=4 _ERROR_=0 _N_=2 Values at beginning of DATA step: City1= City2= City3= Citypop1=25000 Citypop2=65000 Citypop3=115000 Year=1997 Taxyear=1997 Gain=. i=. _ERROR_=0 _N_=3
libname class 'SAS-data-library';
proc sort data=class.allscores;
by id;
run;
data class.bestscores;
drop grade;
set class.allscores;
by id;
/* Prevents HIGHEST from being reset*/
/* to missing for each iteration. */
retain highest;
/* Sets HIGHEST to missing for each */
/* different ID value. */
if first.id then highest=.;
/* Compares HIGHEST to GRADE in */
/* current iteration and resets */
/* value if GRADE is higher. */
highest=max(highest,grade);
if last.id then output;
run;
| See Also |
Statements:
|
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.