ben.powell@CLA.CO.UK (Ben Powell) wrote in message news:<200309251339.h8PDd3v01281@listserv.cc.uga.edu>...
> I'm not clear on what can be done in any single datastep and would
> appreciate any pointers.
> Say for example I want to copy a dataset to my work lib, rename a variable
> and keep that and one other variable. Because in the past I have found that
> sometimes a step won't action unless there is a run command after it I
> would break this job into 3 seperate data steps, which is quite repetative.
> Is there a rule of thumb for when a new datastep is needed and how many
> steps can be included in a datastep?
> data a;
> set lib.a;run;
> data a (rename=(var1=var2));
> set a;run;
> data a;
> set a;
> keep var2 var3;
It seems that there's a misunderstanding of the data step at work
here. Reading any good SAS Data Step programming manual will help; in
the mean time, perhaps it will help to note a couple properties of the
* Each data step is a separate program; it is compiled and executed
separately from every other step in your SAS job. Thus, once you
start thinking of the data step as a separate program in its own
right, you can start to exploit its tremendous power.
* Each data step is an implicit loop. A SAS Data Step manual will
explain A LOT about this fundamental concept.
In the meantime, other posters solved your problem using data set
options. To give you some further insight, the same thing could be
set lib.a (rename (var1=var2));
keep var2 var3;
Picture the above data step as a loop, each iteration reading in one
observation from lib.a (via the set statement) and simultaneously
renaming var1 to var2, then outputting only var2 and var3. You can do
a tremendous amount of other processing in this implicit loop; each
iteration of the loop will carry out the processing on just the
I hope that helps,