LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (September 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Sep 2010 08:23:19 -0500
Reply-To:     "Data _null_;" <iebupdte@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Data _null_;" <iebupdte@GMAIL.COM>
Subject:      Re: monthly update
Comments: To: toby dunn <tobydunn@hotmail.com>
In-Reply-To:  <BAY123-W155321F762150E7118A18DDE740@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1

What you would do or the the variable naming conventions you "allow" has nothing to do with my example. I believe I also mentioned that a different data structure would be preferred.

My example was to address the question how to AGE an enumerated variable list. My interest is how RENAME works.

On 9/10/10, toby dunn <tobydunn@hotmail.com> wrote: > Data _Null_ , > > Personally, if this really was an issue for me, which it isnt, as I do not allow values in my variable names much less this bad of a data struicture. I think i'd just write a macro that pops the meta data, runs a proc datasets with two rename run groups within a modify statement. > > > Toby Dunn > > > "I'm a hell bent 100% Texan til I die" > > "Don't touch my Willie, I don't know you that well" > > > > > > Date: Fri, 10 Sep 2010 07:43:26 -0500 > > From: iebupdte@GMAIL.COM > > Subject: Re: monthly update > > To: SAS-L@LISTSERV.UGA.EDU > > > > Like Mr. Tabachneck I am interested in the how to solve the problem of > > "aging" the variable names. I do agree that the data structure is not > > good but it is interesting to me to consider how to accomplish the > > task of renaming the variables. > > > > I too tried the rename using a descending enumerated list. If you use > > an ascending list there is a variable name clash M0 renamed to M1 > > while original M1 still exists and you get an error.. > > > > The problem with the descending enumerated list is RENAME does not > > recognize the descending list properly, M10 is considered smaller > > than M2 so you get an ERROR start before end. However, if the list > > numbers have leading zeros then the descending rename will work. > > > > M63-M00=M64=M01 > > > > And you could actually rename the values with leading zeros, AGE and > > rename back, all in ONE rename data set option. > > > > M0-M63 = M000-M063 > > M063-M000 = M064-M001 > > M001-M064 = M1-M64 > > > > But even that part is unnecessary as you can just rename the variables > > using an ascending enumerated list with a differnt root and then > > rename them back with a different start and stop, like 1-64 > > > > M0-M63 = ZZ0-ZZ63 > > ZZ0-ZZ63 = M1-M64 > > > > This can all take place in ONE rename data set option and with a > > mechanism to determine the largest value of Mnn can be automated to > > some degree. > > > > > > data Trans; > > do id = 1 to 3; > > m0 = ranuni(1243); > > output; > > end; > > run; > > data Current; > > do id = 1 to 2; > > array m[*] m0-m11; > > do _n_ = 1 to dim(m); > > m[_n_]=_n_; > > end; > > output; > > end; > > run; > > proc print; > > run; > > * Find max index of the M variables; > > proc sql noprint; > > select max(input(substr(name,2),8.)) into :m > > from dictionary.columns > > where libname='WORK' and memname='CURRENT' and upcase(name) eqT 'M' > > ; > > quit; > > run; > > %let M=&m; > > %let P=%eval(&m+1); > > %put NOTE: M=&m P=&p; > > > > data new(/*drop=M&p*/); > > merge trans > > current > > ( > > rename= > > ( > > m0-m&m = _0-_&m > > _0-_&m = m1-m&p > > ) > > ); > > by id; > > run; > > proc contents varnum; > > run; > > proc print; > > run; > > > > NOTE: PROC DATASETS has a similar function in the AGE statement to > > RENAME data sets. This is very useful if you need to keep a number of > > backups of a SAS data set. > > > > On 9/10/10, Arthur Tabachneck <art297@netscape.net> wrote: > > > Chang, > > > > > > While I agree with the others that a redesign would probably be the better > > > solution, one could always use some variant of: > > > > > > data want; > > > set have (rename=(m63-m10=m64-m11 > > > m9=m10 > > > m8-m0=m9-m1)); > > > run; > > > > > > Art > > > ---------- > > > On Thu, 9 Sep 2010 10:51:42 -0400, Chang Chung <chang_y_chung@HOTMAIL.COM> > > > wrote: > > > > > > >An interesting question posted somewhere else. It goes, in part: > > > > > > > >"I've got a data table with text variables named m0, m1 up to m62. Each > > > month > > > >this dataset is updated, with the latest month's data stored in m0 while > > > all > > > >the rest need to move up on index, i.e. m0 should be renamed m1, m1 > > > should be > > > >renamed m2, etc. up to m62 which should be renamed m63." > > > >


Back to: Top of message | Previous page | Main SAS-L page