- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
how to rename multiple variables in a dataset with new numeric variables?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like this ?
data want;
set have;
rename cohort_11 = c11 cohort_12 = c12 cohort_13 = c13;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please be more precise in your diction.
Do you want to rename your variables, or replace them?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Rename
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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