The data comes from the standard SASHELP.CLASS example table.
1 Code Block
DATA STEP Data
Explanation : Using the RETAIN statement to preserve the value of 'totage' from one observation to the next, initialized to 0, and manually adding the age.
Copied!
data totalage;
set sashelp.class;
retain totage 0;
totage = totage+age;
run;
1
DATA totalage;
2
SET sashelp.class;
3
retain totage 0;
4
totage = totage+age;
5
RUN;
2 Code Block
DATA STEP Data
Explanation : Using the Sum Statement 'variable+expression'. This syntax automatically implies RETAIN and handles missing values as zeros for accumulation.
Copied!
data totalage;
set sashelp.class;
totage+age;
run;
1
DATA totalage;
2
SET sashelp.class;
3
totage+age;
4
RUN;
3 Code Block
DATA STEP Data
Explanation : Using the SUM function with explicit RETAIN. The SUM function ignores missing values, unlike the simple '+' operator used in the first example.
Copied!
data totalage;
set sashelp.class;
retain totage 0;
totage = sum(totage,age);
run;
1
DATA totalage;
2
SET sashelp.class;
3
retain totage 0;
4
totage = sum(totage,age);
5
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.