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 (May 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 19 May 1999 16:40:24 -0400
Reply-To:     terry_pennington@NASS.USDA.GOV
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         terry_pennington@NASS.USDA.GOV
Subject:      LOWERCASE
Comments: To: rjf2@CDC.GOV
Content-Type: text/plain; charset=US-ASCII

Any ideas regarding how to convert a macro variable from UPPERCASE to lowercase?

EX. &SURVEY resolves to SMT (or any other number of survey name abbreviations)

Uppercase SMT is used as a switch in a program AND SMT in *lowercase* will always be equivalent to the name of the unix subdir where the data is located for that survey /u/userna/smt or /u/userna/&SURVEY

Ideas?

Thank you!!!

____________________Reply Separator____________________ Subject: Macros: a quick guide Author: "Fehd Ronald J." <rjf2@CDC.GOV> Date: 5/19/99 4:26 PM

From: Srna Carol [mailto:Carol.Srna@m1.irs.gov] /Macro Maven: Please suggest a manual for someone new to writing macros. TIA.

here's what's on my bookshelf today:

SAS Guide to Macro Processing V6 2e 1990 SAS#:?

SAS Tech Report P-222 C&E to BASE SAS R6.07 1991 SAS#:59139 has some stuff on extensions to macro language

SAS Macro Facility Tips & Techniques 1994 SAS#:55097 SAS Users Share Their Macro Expertise: a big collection of SUGI papers

SAS Macro Language Reference 1e 1997 SAS#:55501 recommended: they finally start talking to programmers and use the correct word 'scope' rather than 'referencing environment'

Read 'em and weep.

Art Carpenter's book on macros: I know it's here somewhere, but can't find it at the moment. :-@

Anything ever written anywhere, any time, by Ian Whitlock.

Tips: * SAS is a number-crunching language, SAS macro is a string-processing language. * know SAS well before attempting to use SAS macros to write SAS for you * write SAS twice, before writing SAS macro once * get a life, get a style and stick with it: they'll help you remember where you're at * know where you're at: which side of the step boundary are you on * KISS: Keep It Simple * know your delimiters: SAS delimiters and SAS macro delimiters: the dot will bite you * know your comparison operators and their mnemonic equivalents, else ORegon will bite you * numbers are numbers and can be arithmetically manipulated, in SAS * digits are not always numbers, most times they are strings, in SAS macros

where I started: B.S. in Computer Science, U/HI when I graduated I had some experience in eight languages, more than half of them string-processing languages. I knew the difference between a function, which returns a value and a procedure, which does lotsa stuff.

As I began to learn SAS, I understood that I was working in a number-crunching language. When I first got my SAS User Guide: Basics V5e I read the first couple of chapters then started reading all the functions, looking for the string-processing functions. Know these backwards and forwards: compress, index, indexc, input, left, put, repeat, reverse, right, scan, substr, translate, trim, verify, call label, call symput, call vname. reading up on these and doing your own testing with them will get you familiar with SAS and it's ideas on string-processing.

Then go thru whichever of the macro manuals you decide to have and recognize which SAS functions are in the macro language. The main ones: %compress, %index, %scan, %substr. Do some testing. Comprehend the difference between SAS function int and macro function %eval.

Start using macro variables: %LET VAR = VAR1; notice that macro variables are in your "global environment", just like title statements.

Your begining programs are going to be something like: %LET VARS = VAR1 VAR2; *LET VARS = VAR3 VAR4; proc PRINT data = SOMETHING; var &VARS.; notice how enabling the second %LET statement gets you different output.

Grasp the idea of a macro-variable as a "global constant", and also as a "parameter". Recognize that your SAS mind-set is that a "variable" is part of a data set, and you work with them inside the data step, and don't attempt to change them outside the data step. Macro variables are global, you can change them anywhere and any time!

Style: I have found over the decade that I have written macros that my style sheet helps me remember "where I'm at". If I think that macros are global constants, then I type my macro variables and macro language in all caps, and my SAS language in lower case. That's also a reminder to me the macro language is really simple. Many times when my code is apparently complicated, the ALL CAPS reminds me that it's _really_ simple. 'Simple' will bite you.

Know where you're at: Even though you have one program in front of you, when macros are used there are two things happening: SAS macros generating SAS language, and then SAS language statements. Grasp tokenization. Macros can be used to write SAS language, that includes: SAS 'paragraphs': many SAS statements SAS statements: SAS keywords plus semicolon at the end! SAS 'phrases': one of more 'words' of a SAS statement SAS token: a single SAS 'word'

Write SAS twice, before writing macros once: Identify recurring patterns; why else write macro code? and, of course macro variabless contain the stuff that changes in the pattern.

.. well that's a day's worth of 'getting started' help.

This will be a paper some day. ... LOL ;-D

Ron Fehd the macro maven CDC Atlanta GA


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