Date: Thu, 12 May 2011 14:16:53 -0500
Reply-To: "jonaitis@wisc.edu" <jonaitis@wisc.edu>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Erin McMullen Jonaitis <jonaitis@WISC.EDU>
Organization: WAI
Subject: Re: Strange behavior of rename in data step
In-Reply-To: <BANLkTin4poFk8U9HCZV5YcMvUeCARXtSSg@mail.gmail.com>
Content-Type: text/plain; CHARSET=US-ASCII
YES! That was the problem. Thank you!
Now I have learned something about labels!
(Sorry about the file! - and thanks for the correction.)
Erin
From: Joe Matise [mailto:snoopy369@gmail.com]
Sent: Thursday, May 12, 2011 2:13 PM
To: jonaitis@wisc.edu
Cc: SAS-L@listserv.uga.edu
Subject: Re: Strange behavior of rename in data step
I would guess you're looking at the variable LABELS, not variable NAMES. Some of the methods of putting out CSVs will use variable labels instead of variable names. If you clear the labels (or view variable names), does that solve the problem? Excel import automatically creates variable labels equal to the variable names pre-excel-import-cleaning (so with " " instead of "_" etc.)
Also, you can't attach files on the list :)
-Joe
On Thu, May 12, 2011 at 2:05 PM, Erin McMullen Jonaitis <jonaitis@wisc.edu> wrote:
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 Jonaitis, Ph.D.
Academic Staff Assembly Representative, District 120
Assistant Scientist, Wisconsin Alzheimer's Institute
7818 Big Sky Drive
Madison, WI 53719