BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ANKH1
Pyrite | Level 9

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:

Subjectestimatestandard Error
ID232
ID(group)453

This is the transposed result:

estimate_IDstd_IDestimate_ID(group)std_ID(group)
232453
1 ACCEPTED SOLUTION

Accepted Solutions
mtnbikerjoshua
Obsidian | Level 7

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

View solution in original post

6 REPLIES 6
sbxkoenk
SAS Super FREQ
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

mtnbikerjoshua
Obsidian | Level 7

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

ANKH1
Pyrite | Level 9
Thanks also for explaining!
ballardw
Super User

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.

andreas_lds
Jade | Level 19

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.

ANKH1
Pyrite | Level 9

Oh right! This also works!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 713 views
  • 2 likes
  • 5 in conversation