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 |
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
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
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
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.
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.
Oh right! This also works!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.