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
Content-Type: text/plain; format=flowed
>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
>Appreciate any suggestions..
>/* Code Begins here */
>%let cm_dt = '1sep06'd;
>%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.),
> month = left(substr(put(intnx('month', &cm_dt, &N - 8), yymmddn8.),
> call symput('year', year);
> call symput('month',month);
>libname old_ds "/marketing/data/&year/&month";
> merge old_ds.acct_info (in = key1)
> work.temp11 (in = key2);
> if (key1 and key2)
>%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.
David L. Cassell
3115 NW Norwood Pl.
Corvallis OR 97330
Add fun gadgets and colorful themes to express yourself on Windows Live