- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to use what SAS calls a "name literal".
Just as
- A number, say like 5, is a numeric literal (as in X=5).
- A quoted string is a character literal (as in Y='This is a string')
- A '.....'d is a date literal (renew_date='25Aug2021'd)
- '....'t is a time literal (lunch_time='13:00:00't)
- '...'dt is a datetime literal
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.
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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