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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.