- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello friends,
I have existing dataset XYZ which has space in b/w variable name like below;
finance field
marketing strategy
goal to realign
process in place
now i am trying to using this dataset and wants to rename all above variables...how can i do that - please help.
i am using this logic but its not working.
data test;
set xyz;
rename
finance field=finance_field
marketing strategy=marketing_strategy
goal to realign=goal_to_realign
process in place=process_in_place
;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then post the code that doesn't work.
Encasing the variable with single quotes followed by a n in the rename statement should work.
Post the log from the following code Your original code modified:
data test;
set xyz;
rename
'finance field'n=finance_field
'marketing strategy'n=marketing_strategy
'goal to realign'n=goal_to_realign
'process in place'n=process_in_place
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
1. Check that SAS didn't already do that for you and isn't showing you a label instead of name. Usually it does by default, though EG can be different.
2. Refer to variable with spaces as 'variable name'n
ie 'finance field'n=finance_field
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
i did try that way too but getting both variable into the final dataset;
finance field | finance_field
where "finance field" has value and "finance_field" doesn't have anything....
Also validvarname=any giving that WARNING MESSAGE
WARNING: Only Base procedures and SAS/STAT procedures have been tested for use with VALIDVARNAME=ANY. Other use of this option is considered experimental and may cause undetected errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Post a proc contents from your input dataset?
And/or code/log with any errors messages.
proc contents data=have; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm assuming that this data has been imported into SAS from an external source otherwise you wouldn't have variable names with spaces unless you explicitly coded for them like 'finance field'n.
If you re-run your import code with this option:
options validvarname = V7;
It will automatically rename your SAS variables to replace spaces with underscores.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc contents data=have varnum ; run;
# variable type len format informat label
1 finance field char 16 finance field
2 marketing strategy char 25 marketing strategy
3 goal to realign char 20 goal to realign
4 process in place char 25 process in place
Dataset is already existed and i don't know from which source (row file) or i would reread with my own variable say using "_" in b/w
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What was the encoding reported by proc contents?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In that case this works for me:
options validvarname = Any;
data test;
attrib 'Name with blank'n length = $10;
run;
data test2;
rename 'Name with blank'n = Name_with_blank;
set test;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Encoding = wlatin1 Western (Windows)
Engine = V9
Indexes= 0
OBS length=432
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then post the code that doesn't work.
Encasing the variable with single quotes followed by a n in the rename statement should work.
Post the log from the following code Your original code modified:
data test;
set xyz;
rename
'finance field'n=finance_field
'marketing strategy'n=marketing_strategy
'goal to realign'n=goal_to_realign
'process in place'n=process_in_place
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/*This data step has worked for me - i think we don't need two separate data step for it*/
options validvarname = Any;
data test;
attrib 'Name with blank'n length = $10;
rename 'Name with blank'n = Name_with_blank;
set test;
run;
@ Reeza - your code ran fine too...
Thanks a lot all of you