Modifying Variables

Selected Useful Statements

Here are examples of statements that accomplish specific data-manipulation tasks.
Table 9.4 Manipulating Data Using the DATA Step
Task
Example Code
Subset data
if resthr<70 then delete;  
if tolerance='D';
Drop unwanted variables
drop timemin timesec;
Create or modify a variable
TotalTime=(timemin*60)+timesec;
Initialize and retain a variable
retain SumSec 5400; 
Accumulate totals
sumsec+totaltime;
Specify a variable's length
length TestLength $ 6;
Execute statements conditionally
  if totaltime>800 then TestLength='Long'; 
  else if 750<=totaltime<=800 
    then TestLength='Normal'; 
      else if totaltime<750 
    then TestLength='Short';
The following ...

Get SAS Certification Prep Guide, 5th 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.