Sas Studio-Dealing with Variable Names That Have Spaces

When I load in an excel sheet through PROC IMPORT, locally installed SAS automatically replaces the variable names with spaces to an underscore (_). Such as Patient ID will become Patient_ID and Health Records will become Health_Records.

However, when I load the same file in SAS Studio, that renaming convention isn't applied. So Patient ID and Health Records are kept as is...without the underscore in place.

Thus, how would I call these variables in SAS Studio? A syntax error pops when I try to call IF Patient ID THEN this. Would I have to physically add the underscore to my original dataset or is there an easier way?

2 Answers

The difference is caused by the setting of VALIDVARNAME option.

To refer to variable names with spaces you need to use a name-literal for example.

"Patient ID"n

Quoted string followed by the letter N.

As @data_null_ notes, VALIDVARNAME=ANY is what is causing this.

If you want SAS Studio to behave like your desktop SAS, simply add

options validvarname=v7;

to the top of your program (or to some program that will run before your imports, like an autoexec). Then your underscores will return.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest