- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One of the variable names from results output has a parenthesis, i.e., ID(group). How can I rename the variable? Rename does not work.
I needed to transpose from long to wide the results output but when I wanted to rename id(group) it does not work. This is what the output looks like:
Subject | estimate | standard Error |
ID | 23 | 2 |
ID(group) | 45 | 3 |
This is the transposed result:
estimate_ID | std_ID | estimate_ID(group) | std_ID(group) |
23 | 2 | 45 | 3 |
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ANKH1,
To reference a variable containing a special character in SAS, you need to put the variable name in quotes followed by a letter n. Try this line of code:
rename 'estimate_ID(group)'n=new_name;
Best,
Joshua
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
options validvarname=any;
data have;
input estimate_ID std_ID 'estimate_ID(group)'n 'std_ID(group)'n;
cards;
23 2 45 3
;
run;
proc datasets library=work NoList NoDetails memtype=data;
modify have;
rename 'estimate_ID(group)'n = abc;
rename 'std_ID(group)'n = xyz; run;
QUIT;
/* end of program */
Koen
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ANKH1,
To reference a variable containing a special character in SAS, you need to put the variable name in quotes followed by a letter n. Try this line of code:
rename 'estimate_ID(group)'n=new_name;
Best,
Joshua
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Provide data prior to the Proc Transpose in the form of a working data step and the Proc Transpose code you used.
You will (and likely should) fix the data before the transpose. Since you did not provide the Transpose code I have to guess that you used and ID statement which means that the "problem" lies in the value of the Subject variable if that was used in the ID statement. But you have some other questionable things as well, so an example data set is needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In the first dataset "ID(group)" is a value, so you need a normal assignment to change the value.
data want;
set have;
if Subject = "ID(group)" then Subject = "id_group";
run;
EDIT: Added forgotten quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Oh right! This also works!