|
I suspect the problem is that you've got two macro variables next to each other- try adding a period to end the first one:
%LET FY=2008;
%LET QRTRN=4;
%MACRO FRQCAL;
%DO K = 1 %TO &QRTRN;
DATA FAML&K (DROP=VAR1);
SET FAMILY&FY.&K (KEEP=VAR1 VAR2 VAR3 VAR4);
WHERE VAR1 = 1;
RUN;
%END;
%MEND FRQCAL;
%FRQCAL
So normally you would need a period to indicate the end of the macro variable if the next character is not a space.
-Mary
--- neal.nair@ACF.HHS.GOV wrote:
From: "Nair, Neal K (ACF)" <neal.nair@ACF.HHS.GOV>
To: SAS-L@LISTSERV.UGA.EDU
Subject: A Macro programming question
Date: Thu, 17 Jun 2010 11:35:21 -0400
I am a novice (or less than that - if such a status exists) in macro
programming. I am certain that the question I am raising here is
trivial to many of you, esteemed SAS-Lers. Please forgive me for that.
I have SAS data sets for each Quarter of a year for many years. I am
trying to create four different data sets, one for each Quarter, for a
selected year (in my case FY 2008), keeping only some of the variables
in a data set. The macro program I came up with for that is as follows:
%LET FY=2008;
%LET QRTRN=4;
%MACRO FRQCAL;
%DO K = 1 %TO &QRTRN;
DATA FAML&K (DROP=VAR1);
SET FAMILY&FY&K
(KEEP=VAR1 VAR2 VAR3 VAR4);
WHERE VAR1 = 1;
RUN;
%END;
%MEND FRQCAL;
%FRQCAL
I was hoping to get four different data sets - FAML1, FAML2, FAML3 and
FAML4 - from the above program, which I later combine into one for
additional analysis. But I am not getting those four data sets. [Never
mind the libname issue here]. Moving the two %LET statements inside the
%FRQCAL did not make any difference in the outcome. I think I am
missing something very basic here.
If, instead of the above program, I employ macro parameters, I get the
four desired data sets; the program with macro parameters I developed is
as follows:
%MACRO FRQCAL(FY,QRTRN);
%DO K = 1 %TO &QRTRN;
DATA FAML&K (DROP=VAR1);
SET FAMILY&FY&K
(KEEP=VAR1 VAR2 VAR3 VAR4;
WHERE VAR1 = 1;
RUN;
%END;
%MEND FRQCAL;
%FRQCAL (2008,4)
I would very much appreciate your help in understanding what is wrong
with my first Macro program.
Thanks.
Neal
|