Valid in: | DATA step |
Category: | Information |
Type: | Declarative |
If a variable name is specified only in the RETAIN statement and you do not specify an initial value, the variable is not written to the data set, and a note stating that the variable is uninitialized is written to the SAS log. If you specify an initial value, the variable is written to the data set.
You can also use a shorthand notation for specifying a range of sequential integers. The increment is always +1.
You can assign initial values to both variables and temporary data elements.
If there are more variables than initial values, the remaining variables are assigned an initial value of missing and SAS issues a warning message.
data _null_;
array City{3} $ City1-City3;
array cp{3} Citypop1-Citypop3;
retain Year Taxyear 1999 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
;
Values at beginning of DATA step: City1= City2= City3= Citypop1=10000 Citypop2=50000 Citypop3=100000 Year=1999 Taxyear=1999 Gain=. i=. _ERROR_=0 _N_=1 Values after adding GAIN to city populations: City1= City2= City3= Citypop1=15000 Citypop2=55000 Citypop3=105000 Year=1999 Taxyear=1999 Gain=5000 i=4 _ERROR_=0 _N_=1 Values at beginning of DATA step: City1= City2= City3= Citypop1=15000 Citypop2=55000 Citypop3=105000 Year=1999 Taxyear=1999 Gain=. i=. _ERROR_=0 _N_=2 Values after adding GAIN to city populations: City1= City2= City3= Citypop1=25000 Citypop2=65000 Citypop3=115000 Year=1999 Taxyear=1999 Gain=10000 i=4 _ERROR_=0 _N_=2 Values at beginning of DATA step: City1= City2= City3= Citypop1=25000 Citypop2=65000 Citypop3=115000 Year=1999 Taxyear=1999 Gain=. i=. _ERROR_=0 _N_=3
libname class 'SAS-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;