Iteratively Processing Observations from a Data Set

Previous examples of DATA steps used DO loops to generate one or more observations from one iteration of the DATA step. It is also possible to write a DATA step that reads a data set to compute the value of a new variable.
The SAS data set Finance.CDRates contains interest rates for certificates of deposit (CDs) that are available from several institutions.
Suppose you want to compare how much each CD earns at maturity with an investment of $5,000. The DATA step below creates a new data set, Work.Compare, that contains the added variable, Investment.
data work.compare(drop=i); set finance.cdrates; Investment=5000; do i=1 to years; investment+rate*investment; end; run; proc print data=work.compare ...

Get SAS Certification Prep Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.