Date: Sun, 8 Oct 2006 22:31:43 -0700
Reply-To: David L Cassell <davidlcassell@MSN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: David L Cassell <davidlcassell@MSN.COM>
Subject: Re: Compute macro variables
In-Reply-To: <1160171628.021691.73030@h48g2000cwc.googlegroups.com>
Content-Type: text/plain; format=flowed
mahesh.tamboli@GMAIL.COM wrote:
>
>Hi there,
>
>The code below does the following. Based on the current month computes
>the year and month for the last 12 months and pulls the relevant data .
>The code works, but the issue is the way it is coded. Since 2 new macro
>variables need to be computed based on the current month date, a data
>_NULL_ step is used. Here, I am trying to explore any other
>alternatives that will help me to avoid using a data step (and
>work.cust_data dataset).
>
>Appreciate any suggestions..
>
>Thanks,
>
>/* Code Begins here */
>
>%let cm_dt = '1sep06'd;
>
>%macro auto;
>
>%DO N = 1 %TO 12;
>
> data _NULL_;
> set work.cust_data; /* Uses a existing temp dataset */
>
> format year $CHAR4.;
> format month $CHAR2.;
>
> year = substr(put(intnx('month', &cm_dt, &N - 8), yymmddn8.),
>1,4);
> month = left(substr(put(intnx('month', &cm_dt, &N - 8), yymmddn8.),
>5,2);
> call symput('year', year);
> call symput('month',month);
>
>run;
>
>libname old_ds "/marketing/data/&year/&month";
>
>data result_&N;
> merge old_ds.acct_info (in = key1)
> work.temp11 (in = key2);
> if (key1 and key2)
>run;
>
>%END;
>%mend;
>
>%auto; /* Macro Call */
I see that you have already received sound advice. Let me offer some
griping in addition to what you have already read.
The problem is your bad database design. If you re-organize your data
into a single SAS data set, then one WHERE clause with no macro
variables would suffice.
If you cannot move your /data/year/month/ 'structure' into something
useable, then consider building a data step view that would hold all your
data as a single view, and then you could just query that view as if it
were a real database.
As long as you use a really unwieldy pile of files instead of a real
database design, you will always have these kinds of headaches cropping
up, with struggles to find the right files, and battles with macro code,
and everything else that can go wrong.
HTH,
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330
_________________________________________________________________
Add fun gadgets and colorful themes to express yourself on Windows Live
Spaces
http://clk.atdmt.com/MSN/go/msnnkwsp0070000001msn/direct/01/?href=http://www.get.live.com/spaces/features
|