BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5

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?

 

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

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

Reeza
Super User

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. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 767 views
  • 0 likes
  • 3 in conversation