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 (May 2011, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 13 May 2011 10:20:48 -0400
Reply-To:     "Kirby, Ted" <ted.kirby@LEWIN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Kirby, Ted" <ted.kirby@LEWIN.COM>
Subject:      Re: Strange behavior of rename in data step
Comments: To: Michael Raithel <michaelraithel@WESTAT.COM>
Content-Type: text/plain; charset="iso-8859-1"

MMMIIIKKKEEE, I thought that CHANGE was used to change dataset (file) names, and RENAME was used to change variable names. (I know you do not like to receive responses to your personal e-mail account, but I am using Outlook Webmail and cannot delete your e-mail address from the "To:" line. Sorry.)

________________________________

From: SAS(r) Discussion on behalf of Michael Raithel Sent: Thu 5/12/2011 8:52 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Strange behavior of rename in data step

Dear SAS-L-ers,

Erin posted the following:

> Hi! > > I've been using SAS for about a year and a half. I have version 9.2. > I've seen some odd data step behavior and I'd like to see if anyone > knows why this happens. Sorry if this is long. > > Here's how I've been handling data: > I import data from an Excel file into a temporary dataset. Call it > data_dirty. > Then I create a new dataset from the raw import, where I proceed to > make necessary edits -- clean up missing values, calculate new vars > where needed, etc. > > This week I needed to rename some of my variables, so I used that > dirty->clean data step to do it, like so: > > data cardio; set cardio_dirty (rename=(diabetic=diab1 bpmed=bpmed1 > statin=statin1)); > > This worked fine. Proc print showed the new variables and not the old > ones. I ran my bazillion models and didn't get any errors. I felt > pretty confident my new variables existed. > > Today I exported the same data to CSV so that I could make some > scatterplots in R. When I did that, the CSV file I created did not > have diab1, statin1, or bpmed1 -- it had the old variable names, > diabetic, bpmed, and statin. > > Proc print of my cardio dataset showed me the new variable names. I > tried the export again -- same result: the CSV file had the old names. > Then I opened the data file in "VIEWTABLE". This view of the data > contains the old names. > > I saved my programs, closed SAS, and reopened it. I had already saved > some related permanent datasets. Proc print on one of those showed the > new variable names. Opening the same set in VIEWTABLE showed the old > ones. I've attached a screenshot of the behavior (with data excised). > > Am I missing something obvious because I've been staring at this too > long? Do I need to exorcise my computer? > Erin, yea; given all that you posted, I would definitely call a witch doctor and have the sacred talisman waived over your computer:-)

Not sure what is going on there, but here is a suggestion on a better way to rename variables. Use PROC DATASETS instead of recreating your entire SAS data set in a DATA step. If you have dozens of observations, then no foul; no errors! However, when you have thousands, hundreds of thousands, millions, tens of millions, or the equivalent to the amount of pennies in Bill Gates bank accounts; well, then you are talking about burning a lot of unnecessary computer resources.

If you code something along these lines:

proc datasets library=cardio; modify dirty;

change diabetic = diab1 bpmed=bpmed1 statin=statin1;

run; quit;

...that will change the variable names by simply cutin'-and-pastin'em into the descriptor portion of the SAS data set which usually resides on the first data page of the SAS data set. So, you burn only only several I/O's instead of a boatload.

Um; just read that Joe helped you identify your problem. Nonetheless, consider using PROC DATASETS. Here is a paper that provides more information on this jack of all trades SAS procedure:

PROC DATASETS; The Swiss Army Knife of SAS Procedures, by Michael A. Raithel

http://support.sas.com/resources/papers/proceedings11/274-2011.pdf

Erin, best of luck in all your endeavors!

I hope that this suggestion proves helpful now, and in the future!

Of course, all of these opinions and insights are my own, and do not reflect those of my organization or my associates. All SAS code and/or methodologies specified in this posting are for illustrative purposes only and no warranty is stated or implied as to their accuracy or applicability. People deciding to use information in this posting do so at their own risk.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Michael A. Raithel "The man who wrote the book on performance" E-mail: MichaelRaithel@westat.com

Author: Tuning SAS Applications in the MVS Environment

Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second Edition http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172

Author: The Complete Guide to SAS Indexes http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ If the #2 pencil is the most popular, why is it still #2? - George Carlin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

************* 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