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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

 


 

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

You need to use what SAS calls a "name literal".

 

Just as

  1. A number, say like 5, is a numeric literal   (as in X=5).
  2. A quoted string is a character literal   (as in Y='This is a string')
  3. A  '.....'d is a date literal   (renew_date='25Aug2021'd)
  4. '....'t is a time literal   (lunch_time='13:00:00't)
  5. '...'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

--------------------------
SASKiwi
PROC Star

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; 
Reeza
Super User

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