From the usage note: For example, there are six variables in data set ONE in the positional order of A, B, C, D, E, and F. If the new order needs to be A, E, C, D, B, and F, then the following DATA step reorders the variables in that order: data two;
retain a e c d b;
set one;
run; As noted, the variable F is left off the RETAIN statement since the order of variable F should not change. After running the above DATA step, the variables in data set ONE are in the order of A, E, C, D, B and F. So expanding on the Usage Note: data one;
set sashelp.class;
a=name;
b=age;
c=sex;
d=weight;
e=height;
f=height*weight;
keep a--f;
run;
data two;
retain g a e c d b;
set one;
if c='M' then g='FOO';
run;
data three;
format g a e c d b;
set one;
if c='M' then g='FOO';
run; Compare the output between two and three. IMO the output from two is possibly undesired, and the output from three is as expected. The usage note is good, but IMO should go into more detail of the repercussions of using retain to set the PDV order for a data step (as opposed to data set) variable. Obviously an experienced SAS programmer would know this, but this could catch a newbie.
... View more