|
I have an application with some resemblance to this.
My approach is to have the variable names refer to absolute months.
Instead of renaming, I construct macrovariables to use in referencing the
variables.
For example (not tested):
%let month_latest = 208;
%let month_11back = 109;
In my program these are actually created in a DATA step using CALL SYMPUT.
To continue the example, one could construct a rolling-year total as
totallatex_year =
sum(of totallatex&MONTH_11BACK-totallatex&MONTH_LATEST);
I mention this as one alternative. In general I would favor working with a
normalized structure (one observation per month).
On Tue, 29 Oct 2002 10:22:21 -0500, Chris Smith
<vandalay-industries@WWW.COM> wrote:
>Hello world,
>
>I have a data set that come to me thusly (Example only - I cannot change
>it):
>
>data latexsalesbymonth;
> length identifier $10
> /*name convention is product-year-month*/
> totallatex208 8
> totallatex207 8
> totallatex206 8
> totallatex205 8
> totallatex204 8
> totallatex203 8
> totallatex202 8
> totallatex201 8
> totallatex112 8
> totallatex111 8
> totallatex110 8
> totallatex109 8
> totalneoprene208 8
> totalneoprene207 8
> totalneoprene206 8
> totalneoprene205 8
> totalneoprene204 8
> totalneoprene203 8
> totalneoprene202 8
> totalneoprene201 8
> totalneoprene112 8
> totalneoprene111 8
> totalneoprene110 8
> totalneoprene109 8;
> input identifier totallatex208-totallatex109
> totalneoprene208-totalneoprene109; [sic]
> cards;
> Bob 23 45 60 98 76 54 32 10 yadda yadda yadda...
> Dave 45 67 81 23 45 67 89 20 yadda yadda yadda...
> Mary 32 45 64 73 82 91 10 35 yadda yadda yadda...;
>run ;
>
>It's a rolling data set that is updated monthly, the oldest month dropped
>and newest month added. I want to make a macro (or something) that will
>automatically rename the variables so that the most recent month for each
>product is renamed to "whatever1", and the oldest to "whatever12".
>Example: rename totallatex208=totallatex1
>totallatex207=totallatex2...totallatex109=totallatex12
>totalneoprene208=totalneoprene1
>totalneoprene207=totalneoprene2...totalneoprene109=totalneoprene12
>
>Is there a good way to automate this in a macro or macro/array process? My
>problem is that I have hundreds of products, and far more than 12 months of
>data, and frequently sum them in different temporal combinations (quarters,
>yeard, etc), so as you can imagine I'm doing a lot of intricate and time-
>consuming hard-coding. If I had these variable in a prod1, prod2, prod3...
>construction representing monthly increments, it would really help me
>automate working with it. Thanks in advance.
>
>Chris
|