BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TANMOY05
Obsidian | Level 7

how to rename multiple variables in a dataset with new numeric variables?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The method of renaming variables has already been shown by @ed_sas_member in Message #4 in this thread.

 

As stated above, if you are getting character variables as a result, then something else is wrong, most likely the variables are already character variables. Please show us a PROC CONTENTS output of this data set.

 

If somehow PROC CONTENTS shows these variables as numeric then we need to see the EXACT code you are using to rename, and a PROC CONTENTS on the output data set.

--
Paige Miller

View solution in original post

11 REPLIES 11
ed_sas_member
Meteorite | Level 14

Hi @TANMOY05 

 

Pleas provide some sample data Thank you

TANMOY05
Obsidian | Level 7

like in the following dataset I want to replace variables  cohort_11, cohort_12 and cohort_13 with numeric variable names c11,c12 and c13 respectively. how to do it?

Screenshot (66).png

ed_sas_member
Meteorite | Level 14

Like this ?

 

data want;
	set have;
	rename cohort_11 = c11 cohort_12 = c12 cohort_13 = c13;
run;
TANMOY05
Obsidian | Level 7

yeah but by this method, I am getting character variables, but I want SAS to read the new variables as numeric variables, so how to do this?

 

ballardw
Super User

@TANMOY05 wrote:

yeah but by this method, I am getting character variables, but I want SAS to read the new variables as numeric variables, so how to do this?

 


If the "renamed" variables are character then your original variables are character. You would have to use an input statement for each variable.

 

The picture of the data you show makes be strongly suspect that it is the result of Proc Transpose. If that is the case then likely the best approach would be to create a SINGLE numeric variable from what ever value was transposed with something like:

 

data need;

    set have; /* the set BEFORE transpose*/

    numval = input(charval,best.);

run;

 

Then transpose the data with the NUMVAL instead of your character value.

ed_sas_member
Meteorite | Level 14

Hi @TANMOY05 

 

Ok. So you can use the INPUT function: 

 


data want;
	set have;
	c11 = input(cohort_11,best.);
	c12 = input(cohort_12,best.);
	c13 = input(cohort_13,best.);
run;
TANMOY05
Obsidian | Level 7

But by this method it is not renaming the variables , it is adding up variables c11, c12 and c13 with values of cohort_11, cohort_12 and cohort13 respectively. I want to rename the variables with c11, c12, c13.

TANMOY05
Obsidian | Level 7

Rename

PaigeMiller
Diamond | Level 26

The method of renaming variables has already been shown by @ed_sas_member in Message #4 in this thread.

 

As stated above, if you are getting character variables as a result, then something else is wrong, most likely the variables are already character variables. Please show us a PROC CONTENTS output of this data set.

 

If somehow PROC CONTENTS shows these variables as numeric then we need to see the EXACT code you are using to rename, and a PROC CONTENTS on the output data set.

--
Paige Miller
TANMOY05
Obsidian | Level 7

Yeah, after using proc contents I found out that the variables were already numeric. so now I renamed them as character variables as I needed them as character variables as later in my code I needed to merge datasets. The problem is solved now

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
  • 11 replies
  • 43102 views
  • 0 likes
  • 5 in conversation