| Date: | Wed, 19 Jun 2002 10:20:26 -0500 |
| Reply-To: | Anthony Pitruzzello <statman45@HOTMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Anthony Pitruzzello <statman45@HOTMAIL.COM> |
| Subject: | Some Basics About Macro Variables |
|
| Content-Type: | text/plain; format=flowed |
|---|
I'm new to macro programming. In the last week or so, I have posted two
questions about macros. The responses to those questions have greatly
enhanced my understanding of when and how to use macros. They also raised a
few questions, which I'm asking here. I believe this information would be
very useful to all "macro newbees," not just to me. Let me use some code
from a previous question as a reference:
*** Specify a set of years;
%LET A = 1997; %*Set start year;
%LET B = %EVAL(&A +1);
%LET C = %EVAL(&A +2);
%LET D = %EVAL(&A +3);
%LET E = %EVAL(&A +4);
%LET F = %EVAL(&A +5);
%MACRO RDCTAP;
%DO X=&A %TO &F;
DATA T&X; INFILE TAP&X; INPUT
@10 GRDT&X 2. @17 LVLT&X 2. @19 STBL&X $1. @20 SPC_CODE $3.
@24 BILIND 1. @29 LEPCD 1. @72 SID 8. @166 RPR&X 2.
@635 ACCOM 1. @698 UNT&X 4.;
IF RPR&X < 25 THEN Q&X=1; ELSE Q&X=2;
RUN;
PROC PRINT DATA=T&X (OBS=5);
%END;
%MEND RDCTAP;
%RDCTAP
1) Ian Whitlock advises against using global variables. He prefers
parameters. I can see where the use of parameters is tighter and cleaner.
But here's where I see an advantage to global variables: I like to have a
"Declarations" section at the beginning of my program that acts like a menu.
I can use global variables like "switches." I can change the schools I
include in an analysis, the grades, the years of test scores, whether to
include or exclude special ed populations --all from one place. With
parameters, I would need to page through the program to find and change the
specifications for each macro. Does that seem like a valid design
consideration?
2) I'm still not completely clear about the distinction between macro
variables and data step variables. In the sample code, obviously variables
created with a %LET statement are macro variables. I think the index
variable X, created in "%DO X=&A %TO &F;" is a macro variable. But what
about RPR&X? As I understand it, RPR&X is created in a data step; so it has
to be a data step variable. &X is a macro variable that contributes to
labeling the data step variable (e.g., RPR1997, RPR1998, etc). Does this
comply with the directive from the SAS Guide To Macro Processing, "You can
define and use macro variables anywhere in a SAS program, except within data
lines"? It seems to me that &X is being defined outside the data step but
used within data lines.
If anyone has any thoughts on these issues, I would appreciate hearing from
you.
Regards,
Tony P.
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
|