LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 25 Sep 2003 14:01:50 -0700
Reply-To:   m n <iced_phoenix@YAHOO.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   m n <iced_phoenix@YAHOO.COM>
Organization:   http://groups.google.com/
Subject:   Re: Data Step Question
Content-Type:   text/plain; charset=ISO-8859-1

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? > > e.g. > > data a; > set lib.a;run; > data a (rename=(var1=var2)); > set a;run; > data a; > set a; > keep var2 var3; > run;

Hi Ben,

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 data step:

* 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 accomplished with:

data a; set lib.a (rename (var1=var2)); keep var2 var3; run;

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 current observation.

I hope that helps, Matt


Back to: Top of message | Previous page | Main SAS-L page