BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have an excel file I imported into a SAS dataset. The problem is the excel file column names had spaces. Now the sas dataset columns have the spaces in them too. How do I reference these columns? Also how can I rename them? I tried using quotes in the example below, but got errors trying to run this code.

current dataset:
First Name Last Name
.... ....
.... ....

data test;
keep "First Name";
run;

the above code produces an error. it seems SAS doesn't like the quotes around the column name.

Thanks in advance!
2 REPLIES 2
deleted_user
Not applicable
SAS "name constants"
They have an N suffix in the way that date constants have a D suffix.

Try:[pre]data test ;
keep "First Name"n ;
run ;[/pre]
Also, have a look at system option VALIDVARNAME and SAS/Access to RDBMS documentation

good luck
PeterC
deleted_user
Not applicable
When you import the excel files into SAS, most invalid (in the sense of SAS, like space, $, -, etc ) characters were replaced with _ (under score). Your First Name in excel will become First_Name in SAS. You may be viewing the data file with Column Label. Change to Column Name in data viewer.
You could retain the same variable names with

options VALIDVARNAME=ANY ; (only in BASE and STAT)

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
  • 27542 views
  • 3 likes
  • 1 in conversation