Date: Fri, 1 May 2009 09:34:29 -0500
Reply-To: Robin R High <rhigh@UNMC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Robin R High <rhigh@UNMC.EDU>
Subject: Re: how to upcase varible names in dataset
In-Reply-To: <ce1fb7450905010720r6d898adeocafa2c71f45df023@mail.gmail.com>
Content-Type: text/plain; charset="US-ASCII"
One way to avoid the ERROR message from DATASETS (as I just discovered) is
to add one more qualifier for WHERE part of the SQL code:
WHERE LIBNAME EQ "WORK" AND MEMNAME EQ "A" AND STRIP(NAME) NE
STRIP(LOWCASE(NAME))
if you are converting to lower case (or just have the function on the
right side of NE the same that is in the SELECT part of SQL).
And if there are names to be kept "as they are", other conditions could be
added also
Robin High
UNMC
"./ ADD NAME=Data _null_;" <iebupdte@GMAIL.COM>
Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
05/01/2009 09:26 AM
Please respond to
"./ ADD NAME=Data _null_;" <iebupdte@GMAIL.COM>
To
SAS-L@LISTSERV.UGA.EDU
cc
Subject
Re: how to upcase varible names in dataset
On 5/1/09, Ed Heaton <heatone@comcast.net> wrote:
>
> My final comment is the rhetorical question "Why would you want to make
> your variable names more difficult to read by upper-casing them?"
Exactly! Why do you want this?
However assuming the OP really wants to do this and did not mean "how
to I upcase all the VALUES of the character variables?", it should be
noted that the META data method propose using PROC DATASETS needs a
small qualification. The rename statement in PROC DATASETS works
differently than you might expect.
old-name=new-name
changes the name of a variable in the data set specified in the MODIFY
statement. old-name must be a variable that already exists in the data
set. new-name cannot be the name of a variable that already exists in
the data set or the name of an index, and the new name must be a valid
SAS name.
Therefore if a variable already exists "D" and you try to rename to
"D" you get an error.
58914 data low;
58915 retain a b c D;
58916 stop;
58917 call missing(of _all_);
58918 run;
58919 proc datasets nolist;
58920 modify low;
58921 rename d=D;
ERROR: Variable D already exists on file WORK.LOW.
58922 run;
If you are willing to recreate the data set using a data step then the
VALIDVARNAME option could be useful alternative to the RETAIN method
proposed by Ed..
data low;
retain a b c D;
stop;
call missing(of _all_);
run;
options validvarname=upcase;
data low;
set low;
run;
options validvarname=v7;
proc contents data=low;
run;