LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (December 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 15 Dec 2004 13:51:48 -0800
Reply-To:     cassell.david@EPAMAIL.EPA.GOV
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject:      Re: Need some help with a simple SAS program (using macros).....
In-Reply-To:  <>
Content-type: text/plain; charset=US-ASCII

HoMoon115 <homoon115@YAHOO.COM> wrote: > I'm teaching myself how to use SAS and I've come across a situation > where I'm not quite sure what the correct syntax would be. Anyone have > any suggestions? > > I have a dataset with 4 variables, one of which is called "obs". There > are 50 observations. I'm trying to learn how to use macros. How can I > utilize the macros function to keep specific ranges of observations. > For example say I want to keep all the variables associated with > observations 20-35. > Any help would be much appreciated.

Well, my first advice would be to learn how to do this without thinking about macros. You should look up the various data set options SAS lets you use. In particular, you do *not* need a variable called OBS in your data set, because SAS tracks the observation number for you. (Look up the _N_ internal variable.) So check out the data set options OBS= and FIRSTOBS= . You can get what you want using these.

Then, once you can do this without macros, then you can think about using %LET to assign values to the start and stop points, to get these chunks of the data set for a variety of different values of the cutoffs.

Once you get that far, then consider going to an actual macro, wrapping your code in a macro and using macro parameters instead of those %LET statements.

Still, don't use SAS macro language until you're comfortable with SAS code itself. The macro language is really just a text substitution tool (for the most part), and you need to understand how SAS first parses the macro code and performs the substitutions and then runs the (now-substituted) SAS code afterward.

HTH, David -- David Cassell, CSC Senior computing specialist mathematical statistician

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