Modify a single observation in a SAS data set

synaptik picture synaptik · Apr 10, 2013 · Viewed 17.2k times · Source

Suppose I have the following data set:

data people;
    input name $ age;
    datalines;
Timothy 25
Mark 30
Matt 29
;
run;

How can I change the age of a particular person? Basically, I want to know how to specify a name and tell SAS to change that person's (observation's) age value.

Answer

Joe picture Joe · Apr 10, 2013

The simple case:

data want;
set people;
if name='Mark' then age=31;
run;

You can change it in the same dataset a number of ways:

proc sql;
  update want 
    set age=31 
    where name='Mark';
quit;


data people;
set people;
if name='Mark' then age=31;
run;


data people;
modify people;
if name='Mark' then age=31;
run;

etc.