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 (April 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 15 Apr 2004 17:06:01 +0200
Reply-To:     Ace <b.rogers@VIRGIN.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ace <b.rogers@VIRGIN.NET>
Subject:      Re: variables' renaming
Content-Type: text/plain; charset=us-ascii

>i.e. M200312_a changes to M0_a, M200312_b changes to M0_b ... > M200401_a changes to M1_a, M200401_b changes to M1_b ... > M200402_a changes to M2_a, M200402_b changes to M2_b ... > M200403_a changes to M3_a, M200403_b changes to M3_b...

A little simple code should be able to do this:

data _null_ ; set sashelp.vcolumn end=eof; where libname='WORK' & memname='ORIG' ; if substr(name,5,1)='3' then newname='M0' || substr(name,8,2) ; else newname='M' || substr(name,7,3) ; if _n_ = 1 then call execute ('data work.orig;set work.orig;') ; call execute('rename ' || trim(left(name)) || '=' || trim(left(newname)) || ';') ; if eof then call execute('run;') ; run;

>Next month, I will need to add another month's data to each dataset( by >adding M200404_a M200404_b M200404_c M200404_d ) and also there will be >a new dataset base200403:

I can't help thinking, though, that you'd be much better off simply storing the month (and year) in a separate variable and using the same names for values in each new month, so you'd end up with variables month (currently with values 0,1,2 & 3) , a, b, c and d.

This would be much easier to manage, as well as making any future analyses much morer straightforward.

-- Ace in Basel - brucedotrogers a.t rochedotcom


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