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
photo 1: file in excel replicated with the column name to be changed
photo 2: the code i'm trying to do
photo 3: the error
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.
photo 3**
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.
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;
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.