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 (February 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 23 Feb 2006 12:47:59 -0800
Reply-To:     "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Subject:      Re: Help on macro
Content-Type: text/plain; charset="us-ascii"

To our original poster,

Re: Keeping the learning and using of macros straightforward at first.

Many, many good thoughts, comments, and book references have been posted. I very much second David's thoughts to get familiar with datastep and procs first. We've all seen when the few venturesome folks dive into macros while still in the early learning stages of SAS, get into overly confusing design attempts (as David puts, miserable messes). Just as David eludes to, it's best to only start wanting to employ SAS macros when situations of repetition arise (with consolidating the repetition aspects the emphasis) or when needing "dynamic" parameter feeding. People familiar with other programming language or application background where macro coding is available, where "macros" in those environments really do general processing, often have a tough time getting a hold of the misconception (or perception) that SAS macros actually do general processing in the same sense. SAS Institute's macro facility may be quite different conceptually but is actually quite simple in concept and many times allows for even more complex dynamic solutions. Folks in our neck of the woods find the idea of "text-substitution" is a quick way to wean themselves from the misperceptions and grasp the power and flexibility in SAS macros.

A very elementary LayPerson's Macro-101 can be found at: http://listserv.uga.edu/cgi-bin/wa?A2=ind0512B&L=sas-l&P=R29031

Even as folks become intermediate and advanced users of SAS, I ditto David's recomendation "Try not to fall into that trap", of using SAS macros too often or too early, until you gain an understanding of where they are best applied.

Lots of times nowadays, good, normalized data and 4GL joins can actually replace the interaction of 3GL parameters and processing.

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investment Group

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of David L Cassell Sent: Thursday, February 23, 2006 11:39 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Help on macro

kog@SSB.NO replied: >Hi, you are indeed asking a lot here.. The subject line could well >read: "Please teach me a lot about this macro facility". You can't >expect that to happen. You'll need to study yourself, by practising and

>reading. Besides the SAS documentation a really good book is >Carpenter's: >http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=59224

> >I am new to SAS as well new to SAS Macro. > >A good advice, if you are new to SAS/Base in general: *wait* with macro

>coding. Many questions on macro here indicate that quite a few should >focus more on the Base language (i.e. open code) before jumping on to >macros. It's up to you though.. > > >It would great help if you > >could help me. > >The below are few questions which i would like to know > > > >1)why macros are used and when should we think of writing macros(on > >what basis),what are things we should look before writing macros. > >Macros generate code, so it is often used when there are patterns in >the code. Conditionally generating code is another imp. aspect, for >example based on parameters you supply. > > > >2)Can we use SAS variable inside the macro,if not why? > >The macro part is compiled and executed prior to the datasteps and >procs, so the answer is kind of "no". > > >3)when to use &,&&,and &&&,how do we distinguish. > >Read all about it in the docs or Carpenter's book. > > >4)what is the diff between Single dot and double dot(eg. &chech. and > >&check..) > > > >See [long URL] > >http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_91/ >base_macro_6997.pdf > >page 28.

Okay, first I wanted to say that this was a great response.

Then I wanted to babble a bit to our original poster.

People have a tendency to leap into SAS macros too early, in my opinion. SAS macros are a *huge* and invaluable tool. But if you only know macro, then everything looks like a macro problem. So take everyone's advice and focus on SAS data steps and procs first. Learn what you can do without macro, so you will better understand when you do want to use the tools.

As Arild and others have said, SAS macro gives you the ability to generate text. (Essentially) once that text has been written out, then the SAS code gets run. So trying to mix SAS code and macro code gets most beginners into miserable messes.

SAS macro code can help a lot if you have a problem like:

[1] You have to do one process if the data set has less than 1000 records, and a different process if the data set has at least 1000 records.

[2] You have a pile of maybe a hundred repetitive IF-THEN-ELSE statements that could all be generated automatically if only you had a text generator.

The problem is that people learn some macro basics, and then they start using SAS macro to do stuff for which SAS has better tools. Tools they don't use yet, because they learned about macros instead of learning more about data steps and procs first. Try not to fall into that trap.

HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330

_________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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