LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 11 Mar 2010 12:53:24 -0500
Reply-To:     Arthur Tabachneck <art297@NETSCAPE.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Arthur Tabachneck <art297@NETSCAPE.NET>
Subject:      Re: Changing Variable Names en masse
Comments: To: "Kirby, Ted" <ted.kirby@LEWIN.COM>

Ted,

How about something like:

data have1; input a b c; cards; 1 2 3 ;

data have2; input a b c; cards; 4 5 6 ;

proc sql noprint; select trim(name)||"=first_"||name, trim(name)||"=second_"||name into :first separated by " ", :second separated by " " from dictionary.columns where libname eq "WORK" and memname eq "HAVE1"; quit;

data want1 (rename=(&first.)); set have1; run;

data want2 (rename=(&second.)); set have2; run;

HTH, Art --------- On Thu, 11 Mar 2010 12:25:34 -0500, Kirby, Ted <ted.kirby@LEWIN.COM> wrote:

>Thanks to Jack, Mike and oloolo for your responses. For simplicity's >sake, I had listed the variables as Var1 to Var50, however, the actual >variable names are quite different. Thus the listing of the variables >as Var1-Var50 will not work. To use the array-based solutions, I would >still have to type the 50 variable names with and without the prefixes >and it was that typing of 150 variable names I was trying to avoid. > > > >I was hoping for something that would read the variable names and >programmatically add the new prefixes to them such the following attempt >at pseudo-code. > > > >Data first; > ><get first variable name> > ><add the prefix "First" to the variable name> > ><get the next variable name> > ><add the prefix "First" to the variable name> > >Etc. down to > ><Get 50th variable name> > ><add the prefix "First" to the variable name> > >Run; > > > >Data second; > ><get first variable name> > ><add the prefix "Second" to the variable name> > ><get the next variable name> > ><add the prefix "Second" to the variable name> > >Etc. down to > ><Get 50th variable name> > ><add the prefix "Second" to the variable name> > >Run; > > > ><merge "First" and "Second" datasets as in my original code> > > > >(oloolo: I was able to read only the first few pages of your paper from >the link you provided, so I am not sure whether the program in your >paper did this.) > > > >From: Kirby, Ted >Sent: Thursday, March 11, 2010 10:53 AM >To: 'SAS-L@LISTSERV.UGA.EDU' >Subject: Changing Variable Names en masse > > > >I have a dataset of hospital discharges with several dozen variables. I >have identified pairs of consecutive observations that I would like into >one very long "episode of care" observation. To do that, I need to >differentiate the variable names in the two halves of the episode. Is >there a way to do that en masse? The following illustrates what I would >like to do. > > > >Have: > >BeneID EpisodeNumber Var1 Var2 . . . Var50 > >a 1 <50 values> > >a 1 <50 values> > >b 1 <50 values> > >b 1 <50 values> > >b 2 <50 values> > >b 2 <50 values> > >Etc. > > > >Want: > >BeneID EpisodeNumber FirstVar1 FirstVar2 . . . >FirstVar50 SecondVar1 SecondVar2 . . . SecondVar50 > >1 1 <100 values> > >2 1 <100 values> > >2 2 <100 values> > > > >I had thought to separate the two parts of the Episode into two >databases, renaming the variables, then merging them back together by >BeneID and EpisodeNumber. I would like to be able to rename all the >variables without using 100 RENAME entries as illustrated below. > > > >Data FirstHalf SecondHalf; > >Set have; > >By BeneID EpisodeNumber; > >If first.BeneID or first.EpisodeNumber then output FirstHalf; > >else output SecondHalf; > >Run; > > > >Data FirstHalf; > >Set FirstHalf; > >Rename Var1=FirstVar1 > > Var2=FirstVar2 > > . > > . > > . > > Var50=FirstVar50; > >Run; > > > >Proc sort; data=FirstHalf; by BeneID EpisodeNumber; run; > > > ><similar code for SecondHalf renaming Var1 - Var50 as SecondVar1 - >SecondVar50 and sorting> > > > >Data episodes; > >Merge FirstHalf SecondHalf; > >By BeneID EpisodeNumber; > >Run; > > > >Thanks for any assistance you can render. > > > > >************* IMPORTANT - PLEASE READ ******************** > >This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately. >


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