Date: Thu, 12 May 2011 14:05:32 -0500
Reply-To: "email@example.com" <firstname.lastname@example.org>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Erin McMullen Jonaitis <jonaitis@WISC.EDU>
Subject: Strange behavior of rename in data step
Content-Type: text/plain; CHARSET=US-ASCII
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 Jonaitis, Ph.D.
Academic Staff Assembly Representative, District 120
Assistant Scientist, Wisconsin Alzheimer's Institute
7818 Big Sky Drive
Madison, WI 53719