Desktop productivity for business analysts and programmers

How to deal with variable name having space in SAS Enterprise Guide

Accepted Solution Solved
Reply
N/A
Posts: 0
Accepted Solution

How to deal with variable name having space in SAS Enterprise Guide

I am new to SAS Enterprise Guide. When I used SAS 8.2, if the variable name has space in between, SAS will automatically add "_". But it seems that EG will leave the space in the variable name. So is there any systemic way to deal with it? For example, I have 100 variables in my raw data. After I import it to SAS, is it possible to add "_" for the space for the variable name automatically? Thanks!

Accepted Solutions
Solution
‎08-14-2017 02:04 PM
SAS Super FREQ
Posts: 306

Re: How to deal with variable name having space in SAS Enterprise Guide

Also, in v6.1, Enterprise Guide added a Naming options section in Tools->Data->Data General that allows you to control the default valid variable and member naming rules (still defaults to validvarname=any and validmemname=extend).  You can change it to V7 if desired to go back to the more restrictive naming rules.

deleteme.png

View solution in original post


All Replies
Super Contributor
Posts: 260

Re: How to deal with variable name having space in SAS Enterprise Guide

It is related to the VALIDVARNAME=ANY system option used by EG. This will allow any character to be part of a SAS variable name. Can it be totally turned out for the whole SAS EG session ? I don't see how, but this would be the quickest answer to your problem.
Otherwise, you can create a RENAME statement using macros to replace blanks by underscores. Something like that :
[pre]
OPTION VALIDVARNAME = ANY ;
DATA work.test ;
INPUT "my spaced name 1"n "my spaced name 2"n myRegular_SAS_name ;
CARDS ;
1 1 3
1 2 3
;
RUN ;
PROC PRINT DATA = work.test ;
RUN ;
PROC CONTENTS DATA = work.test OUT = work.dictionary NOPRINT ;
RUN ;
PROC SQL NOPRINT ;
SELECT CATS(NLITERAL(name),"=",TRANSLATE(STRIP(name),"_"," ")) INTO : renameList SEPARATED BY " "
FROM work.dictionary
WHERE STRIP(name) CONTAINS " "
;
QUIT ;
PROC DATASETS LIB = work NOLIST ;
MODIFY test ;
RENAME &renameList ;
RUN ; QUIT ;
PROC PRINT DATA = work.test ;
RUN ;
[/pre]
Regards.
Olivier
N/A
Posts: 1

Re: How to deal with variable name having space in SAS Enterprise Guide

Solution
‎08-14-2017 02:04 PM
SAS Super FREQ
Posts: 306

Re: How to deal with variable name having space in SAS Enterprise Guide

Also, in v6.1, Enterprise Guide added a Naming options section in Tools->Data->Data General that allows you to control the default valid variable and member naming rules (still defaults to validvarname=any and validmemname=extend).  You can change it to V7 if desired to go back to the more restrictive naming rules.

deleteme.png

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 26674 views
  • 2 likes
  • 4 in conversation