DATA Step, Macro, Functions and more

Spaces in Variable Names;SAS name errors

Reply
Contributor
Posts: 59

Spaces in Variable Names;SAS name errors

I have variables that have spaces

Example Variable Names

B GGR

F CCR

in my program I converted the variables using an assignment as follows:

data test;

set test1;

B_GGR = 'B GGR',n;F_CCR='F CCR'n;

run;

I get errors

B GGR is not a valid sas name.

F CCR is not a valid sas name.

Should not the use of the '',n resolve the issue with variables that have spaces?

 

Super Contributor
Posts: 1,636

Re: Spaces in Variable Names;SAS name errors

Posted in reply to omega1983

do you want label your variables or create new variables?

data have;

input B_bb$;

cards;

AA

BB

;

data want;

  set have;

  label b_bb='B BB';

proc print data=want label;

run;

                                                        Obs    B BB

                                                         1       AA

                                                         2       BB

Super User
Posts: 19,822

Re: Spaces in Variable Names;SAS name errors

Posted in reply to omega1983

If you truly have variables with spaces in the name then yes, the ''n notation should allow them to work, however SAS will sometimes convert them itself, but leaves the labels with the spaces.

You can run a proc contents on your dataset to see if that happened.

You can also try the

option validvarname=any;

to see if that helps. 

Ask a Question
Discussion stats
  • 2 replies
  • 193 views
  • 0 likes
  • 3 in conversation