Date: Mon, 22 Jan 2007 13:16:55 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Novice question: rename variables in sas7bdat file
In-Reply-To: <1169404210.983045.317510@q2g2000cwa.googlegroups.com>
Content-Type: text/plain; format=flowed
Seeker ,
IF you maxed out the macro variable and you checked that you were not
putting extra white spcaes where they are not needed, then I would say that
you have way too damned many variables or there names are way too damned
long. In any event it is a minor thing to tweak the code I sent you to
handle as many variables as you want even if the names are the max length.
Data One ;
_111_ = 1 ;
_112_ = 2 ;
_113_ = 'A' ;
_114_ = 'B' ;
;
Run ;
FileName MyVars Temp ;
Data _Null_ ;
File MyVars ;
Set SASHelp.VColumn End = EOF ;
Where Libname = 'WORK'
And Memname = 'ONE' ;
Temp = Name || ' = ' || Cats( 'Var' , VarNum ) ;
If ( _N_ = 1 ) Then Put 'Rename ' ;
Put Temp ;
If EOF Then Put ';' ;
Run ;
Proc Datasets Lib = Work ;
Modify One ;
%Include MyVars ;
Run ;
Quit ;
Proc Contents
Data = One ;
Run ;
Toby Dunn
To sensible men, every day is a day of reckoning. ~John W. Gardner
The important thing is this: To be able at any moment to sacrifice that
which we are for what we could become. ~Charles DuBois
Don't get your knickers in a knot. Nothing is solved and it just makes you
walk funny. ~Kathryn Carpenter
From: Seeker <zhongming@GMAIL.COM>
Reply-To: Seeker <zhongming@GMAIL.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Novice question: rename variables in sas7bdat file
Date: Sun, 21 Jan 2007 10:30:12 -0800
Hi, Toby
Thanks for your quick response!
I tried your code. If I understand it correctly, you use "NewNames" to
store all of "OLDNAME=NEWNAME" statements. It works fine when the
amount of variables is not very big. In my case, I met an error due to
the limit of the text expression length. The length of the macro
variable "NewNames" exceeded the maximum length and got truncated. How
can I circumvent the problem?
Have a great weekend!
Ming
On Jan 20, 6:25 pm, tobyd...@HOTMAIL.COM (toby dunn) wrote:
> Data One ;
> _111_ = 1 ;
> _112_ = 2 ;
> _113_ = 'A' ;
> _114_ = 'B' ;
> ;
> Run ;
>
> Proc SQL ;
> Select Name || ' = ' || Cats( 'Var' , VarNum ) Into : NewNames Separated
by
> ' '
> From Dictionary.Columns
> Where LibName = 'WORK'
> And MemName = 'ONE' ;
> Quit ;
>
> Proc Datasets Lib = Work ;
> Modify One ;
> Rename &NewNames ;
> Run ;
> Quit ;
>
> Proc Contents
> Data = One ;
> run ;
>
> Toby Dunn
>
> To sensible men, every day is a day of reckoning. ~John W. Gardner
>
> The important thing is this: To be able at any moment to sacrifice that
> which we are for what we could become. ~Charles DuBois
>
> Don't get your knickers in a knot. Nothing is solved and it just makes
you
> walk funny. ~Kathryn Carpenter
_________________________________________________________________
Search for grocery stores. Find gratitude. Turn a simple search into
something more.
http://click4thecause.live.com/search/charity/default.aspx?source=hmemtagline_gratitude&FORM=WLMTAG