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

Hi, I imported an xls file (with a variable named ‘VAR ONE’) in a dataset work.test

I know that it is not a valid SAS name of variable.

In the dataset the name of the variable is still ‘VAR ONE’, and I can’t use it.

I tried:

 

Data work.test2 (rename=([VAR ONE]= VAR_ONE));

Set work.test;

Run;

 

But it doesn’t work.

Can you help me?

Thank you all.

zaghini

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you have the option setting of Validvarname=Any then things like proc import will allow non-standard names. These variable names must be used as a name literal which means the text enclosed in quotes followed by the letter n such as 'Var one'n .

 

Additionally you can set the option Validvarname=V7; to prevent proc import from creating such names. The V7 option would create variable names with an underscore character, _ , in the place of any non-letter or non-digit character appearing in the data source as a variable name.

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Set 

 

options validvarname=v7;

before your PROC IMPORT.

ballardw
Super User

If you have the option setting of Validvarname=Any then things like proc import will allow non-standard names. These variable names must be used as a name literal which means the text enclosed in quotes followed by the letter n such as 'Var one'n .

 

Additionally you can set the option Validvarname=V7; to prevent proc import from creating such names. The V7 option would create variable names with an underscore character, _ , in the place of any non-letter or non-digit character appearing in the data source as a variable name.

Zaghini
Fluorite | Level 6

I did:

options validvarname=v7;

PROC IMPORT DATAFILE="/…/test.xls" OUT=work.vincolati DBMS=XLS REPLACE;

      SHEET="Quadratura collegati";

RUN;

 

but in xls file I've the variable 'Bilancio 2021' and in work.vincolati I still have the variable 'Bilancio 2021' instead 'Bilancio_2021' that I would expect with the options validvarname=v7.

where am I wrong?

 

Zaghini
Fluorite | Level 6

I’ve done it!

The problem was that I submitted sas code in separated steps:

  • Libname
  • options validvarname=v7;
  • proc import

and does not work.

But if I do it in 2 steps (or 1) it works:

  • select and submit libname
  • select and submit both options and import

thank you @Kurt_Bremser and @PeterClemmensen and @ballardw

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3619 views
  • 0 likes
  • 4 in conversation