Date: Thu, 19 Jan 2006 02:56:09 -0500
Reply-To: "SASsy :-)" <sas__l@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "SASsy :-)" <sas__l@HOTMAIL.COM>
Subject: Re: Macro to handle changing column names?
On Wed, 18 Jan 2006 23:37:05 -0500, Brian Bachman <bsquared@CTC.NET> wrote:
[see below]
If you know their positions for sure, then you can get the variable names
into macro variables with a snippet like this
(here vars 1 to 6..) :
%macro varnames (ds= );
%let dsid=%sysfunc(open(&ds));
%do i=1 %to 6;
%global var&i;
%let var&i = %sysfunc(varname(&dsid ,&i));
%end;
%let rc=%sysfunc(close(&dsid));
%mend varnames;
data test;
input var1_200502 var1_200503 var1_200504 var2_200502 var2_200503
var2_200504;
cards;
run;
%varnames(ds=test);
%put _user_;
and then use these in your equation.. will that work?
>Sorry to place this here but after searching the archives I couldn't find
>what I was looking for. (I suspect I wasn't describing it correctly).
>
>My problem is this. I have a data set that has year and month as part of
the
>column name (eg. Var1_200501 var1_200502, etc...) There are many columns
>like this and six unique year/month combinations associated with these. A
>new data set is generated every month and the year/month suffix will
change.
>Now. I have an equation of a familiar form y= int +
>
>(B1*var1_200501)+(B2*var1_200502)+(B3*var1_200506)+(B4*var2_200502)+(B5*
>
>var2_200504)+... I guess I am asking for help in identifying a simple
>strategy for creating an association between the columns required for my
>equation given that the actual column suffixes will change but be in a
>predictable sequence every time a new data set is presented. For example if
>presented with var1_200510 var1_200511 var1_200512 var1_200601
>
>var1_200602 var1_200603, the program should be able to automatically equate
>these variables to the positions originally occupied by variables
>var1_200501--var1_200506.
>
>Is this at all clear? My macro skills have really gone to pot in the past
>few years and am hoping that someone can point me in the right direction.
>
>TIA and best regards,
>
>Brian