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

I'm trying to change a name of variable but the variable inside the excel file has spaces and a hyphen (idk if this interferes in anything) and when i'm putting it to assign a new name,a parte of it is in red and i do not can change

 

gbatista_0-1642608867806.png

photo 1: file in excel replicated with the column name to be changed

 

gbatista_1-1642608994012.png

photo 2: the code i'm trying to do

 

gbatista_2-1642609052206.png

 

photo 3: the error

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Post your code as text not images. 

 

You forgot the RENAME statement for starters. Your code would reassign variables, not rename them. 

 

Here's how a rename should work. 

data class;
set sashelp.class;
rename sex = gender;
run;

Verify the actual names in your data set using PROC CONTENTS:

proc contents data=class;run;

Make sure to also refer to the name using the name literal format. 

 

 

View solution in original post

5 REPLIES 5
gbatista
Calcite | Level 5

gbatista_0-1642609131260.png

photo 3**

Reeza
Super User

Post your code as text not images. 

 

You forgot the RENAME statement for starters. Your code would reassign variables, not rename them. 

 

Here's how a rename should work. 

data class;
set sashelp.class;
rename sex = gender;
run;

Verify the actual names in your data set using PROC CONTENTS:

proc contents data=class;run;

Make sure to also refer to the name using the name literal format. 

 

 

PaigeMiller
Diamond | Level 26

For large datasets, the DATA step approach using RENAME is incredibly inefficient.

 

Better: you should get in the habit of using PROC DATASETS if all you want to do is rename a variable.

 

proc datasets library=work nolist;
    modify yourdatasetname;
    change oldvariablename=newvariablename;
run;
quit;
--
Paige Miller
Reeza
Super User
There's also a WHERE clause in that code though....
PaigeMiller
Diamond | Level 26

@Reeza wrote:
There's also a WHERE clause in that code though....

I said: "... get in the habit of using PROC DATASETS if all you want to do is rename a variable."

 

So I think we agree.

--
Paige Miller

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
  • 5 replies
  • 903 views
  • 6 likes
  • 3 in conversation