Hello everybody
I have existing dataset covid which has space in variables name like below:
numero expediente del paciente
I tried renaming them assuming SAS would turn spaces into underscores but when I run the program it sends a warning that the variable does not exist in the dataset. I have run PROC CONTENTS and the variables are there, but the variable name appears without underscores. The original data came from an excel file but I changed it into SAS data.
Here's the code:
libname COVIDBD '/home/mercedesaguilars0/sasuser.v94/SASMer';
data base;
set covidbd.covid;
run;
NOTE: There were 398 observations read from the data set COVIDBD.COVID.
data base2;
set base
(rename=(numero_expediente_del_paciente=numexp));
run;
Variable numero_expediente_del_paciente is not on file WORK.BASE2
Thank you
Set this option and reimport your data to avoid the issue entirely.
options validvarname = v7;
If you have this option set, when you import data SAS will automatically add the underscores to the variable names as necessary.
@MerAgSo wrote:
Hello everybody
I have existing dataset covid which has space in variables name like below:
numero expediente del paciente
I tried renaming them assuming SAS would turn spaces into underscores but when I run the program it sends a warning that the variable does not exist in the dataset. I have run PROC CONTENTS and the variables are there, but the variable name appears without underscores. The original data came from an excel file but I changed it into SAS data.
Here's the code:
libname COVIDBD '/home/mercedesaguilars0/sasuser.v94/SASMer';
data base;
set covidbd.covid;
run;NOTE: There were 398 observations read from the data set COVIDBD.COVID.
NOTE: The data set WORK.BASE has 398 observations and 199 variables.
data base2;
set base
(rename=(numero_expediente_del_paciente=numexp));run;
Variable numero_expediente_del_paciente is not on file WORK.BASE2
Thank you
You need to use what SAS calls a "name literal".
Just as
There are some others too (hexadecimal literals come to mind).
But you need to use a name literal, expressed as 'this is a variable name'n. So in your example, you probably should use
set base
(rename=('numero expediente del paciente'n=numexp));
SAS does NOT replace blanks in a name with underscores.
If your variable names contain spaces then you will probably need to do something like this:
data base2;
set base
(rename=('numero expediente del paciente'n = numexp));
run;
Set this option and reimport your data to avoid the issue entirely.
options validvarname = v7;
If you have this option set, when you import data SAS will automatically add the underscores to the variable names as necessary.
@MerAgSo wrote:
Hello everybody
I have existing dataset covid which has space in variables name like below:
numero expediente del paciente
I tried renaming them assuming SAS would turn spaces into underscores but when I run the program it sends a warning that the variable does not exist in the dataset. I have run PROC CONTENTS and the variables are there, but the variable name appears without underscores. The original data came from an excel file but I changed it into SAS data.
Here's the code:
libname COVIDBD '/home/mercedesaguilars0/sasuser.v94/SASMer';
data base;
set covidbd.covid;
run;NOTE: There were 398 observations read from the data set COVIDBD.COVID.
NOTE: The data set WORK.BASE has 398 observations and 199 variables.
data base2;
set base
(rename=(numero_expediente_del_paciente=numexp));run;
Variable numero_expediente_del_paciente is not on file WORK.BASE2
Thank you
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 16. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.