Date: Fri, 27 Mar 2009 12:58:11 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Help with Renaming
Content-Type: text/plain; charset=ISO-8859-1
Lots of ways. Perhaps the easiest for you to see, is to say:
%let var1 = Feb09
%let var2 = Jan09
%let var3 = Dec08
and then when the next month comes, just move all of the right-hand
arguments down one (copy+paste) and add a new one:
%let var1 = Mar09
%let var2 = Feb09
%let var3 = Jan09
and then in the code, have:
input ID $2 Var_&var1 Var_&var2 Var_&var3 etc.;
%let inputstring = Var_Feb09 Var_Jan09 Var_Dec08 ... ;
input id $2 &inputstring;
and just add Var_Mar09 at the front and delete the last item in the list
These are fairly manual solutions, but it's not really much manual work and
it's entirely transparent.
There are lots of other ways, including writing a macro to determine the
last months based on just one macro variable, or using PROC SQL to create a
table of months and rename from there, etc., depending on how manual you
want your solution to be vs. how complex.
On Fri, Mar 27, 2009 at 12:45 PM, <firstname.lastname@example.org> wrote:
> I have data as shown below:
> data test;
> input ID $2 VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 2.;
> 11 3 2 18 12 6 9 21 26
> 13 8 12 13 12 14 19 24 26
> 16 14 12 13 12 14 19 24 26
> 14 19 11 15 17 6 3 5 17
> I want to rename the variable names Var1-Var8 to the names based on
> the date.
> Each month I get this data. So for example based on Feb 2009 data, I
> want to rename
> Var1 = Var_Feb09 Var2=Var_Jan09 Var3=Var_Dec08 Var4=Var_Nov08 and
> so on...
> I would appreciate any help with renaming.